Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

specify type parameters for base class of HTTPHeaders #3329

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion tornado/httputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
from asyncio import Future # noqa: F401
import unittest # noqa: F401

StrMutableMapping = collections.abc.MutableMapping[str, str]
else:
StrMutableMapping = collections.abc.MutableMapping

Comment on lines +65 to +68
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python 3.8 doesn't support type parameters on MutableMapping, but mypy/Pyright know how to handle them. Once Python 3.8 support is dropped, they can go right in the class definition: HTTPHeaders(collections.abc.MutableMapping[str, str]).


@lru_cache(1000)
def _normalize_header(name: str) -> str:
Expand All @@ -73,7 +77,7 @@ def _normalize_header(name: str) -> str:
return "-".join([w.capitalize() for w in name.split("-")])


class HTTPHeaders(collections.abc.MutableMapping):
class HTTPHeaders(StrMutableMapping):
"""A dictionary that maintains ``Http-Header-Case`` for all keys.

Supports multiple values per key via a pair of new methods,
Expand Down