pyright icon indicating copy to clipboard operation
pyright copied to clipboard

`__required_keys__` and `__optional_keys__` are not inherited from `TypedDict`

Open not-my-profile opened this issue 2 years ago • 1 comments

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).

not-my-profile avatar Jan 04 '23 10:01 not-my-profile

Thanks for the bug report. This will be addressed in the next release.

erictraut avatar Jan 04 '23 12:01 erictraut

This is addressed in pyright 1.1.288, which I just published. It will also be included in a future release of pylance.

erictraut avatar Jan 11 '23 04:01 erictraut