tornado icon indicating copy to clipboard operation
tornado copied to clipboard

Inaccurate typing on HTTPHeaders

Open mslynch opened this issue 2 years ago • 0 comments

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.

mslynch avatar Sep 28 '23 17:09 mslynch