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

Inaccurate typing on HTTPHeaders #3328

Closed
mslynch opened this issue Sep 28, 2023 · 0 comments · Fixed by #3393
Closed

Inaccurate typing on HTTPHeaders #3328

mslynch opened this issue Sep 28, 2023 · 0 comments · Fixed by #3393

Comments

@mslynch
Copy link
Contributor

mslynch commented Sep 28, 2023

HTTPHeaders.get should return str | None, but type checkers aren't able to infer that because it extends MutableMapping without type parameters:

from typing_extensions import reveal_type
from tornado.httputil import HTTPHeaders

h = HTTPHeaders()
reveal_type(h.get('a-header'))

yields Union[Any, None] on mypy and Unknown | None on Pyright.

Adding the type parameters [str, str] to the extended MutableMapping would correct the type to str | None.

bdarnell added a commit to bdarnell/tornado that referenced this issue Jun 7, 2024
Revealed an issue in websocket.py in which bytes were used when it
should have been str. This avoided being a bug because something
down the line was converting it to str but it was still a logical
type error.

The change to httputil.py was taken from tornadoweb#3329 (thanks mslynch).

Closes tornadoweb#3329
Fixes tornadoweb#3328
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant