pyright
pyright copied to clipboard
`__required_keys__` and `__optional_keys__` are not inherited from `TypedDict`
from typing import TypedDict
class Foo(TypedDict): ...
reveal_type(Foo.__required_keys__)
reveal_type(Foo.__optional_keys__)
Mypy correctly reports:
foo.py:5: note: Revealed type is "builtins.frozenset[builtins.str]"
foo.py:6: note: Revealed type is "builtins.frozenset[builtins.str]"
whereas pyright 1.1.287 reports:
/tmp/foo.py
/tmp/foo.py:5:17 - error: Cannot access member "__required_keys__" for type "Type[Foo]"
Member "__required_keys__" is unknown (reportGeneralTypeIssues)
/tmp/foo.py:5:13 - information: Type of "Foo.__required_keys__" is "Unknown"
/tmp/foo.py:6:17 - error: Cannot access member "__optional_keys__" for type "Type[Foo]"
Member "__optional_keys__" is unknown (reportGeneralTypeIssues)
/tmp/foo.py:6:13 - information: Type of "Foo.__optional_keys__" is "Unknown"
2 errors, 0 warnings, 2 informations
The relevant typeshed code is:
https://github.com/microsoft/pyright/blob/440d54d68dba4505d1ba85e44abca27f8c5f5486/packages/pyright-internal/typeshed-fallback/stdlib/typing.pyi#L792-L797
(And my Python version is 3.9.2 so this check should evaluate to true ... I ran pyright with --pythonversion 3.9
to make sure but that didn't change anything).
Thanks for the bug report. This will be addressed in the next release.
This is addressed in pyright 1.1.288, which I just published. It will also be included in a future release of pylance.