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

__required_keys__ and __optional_keys__ are not inherited from TypedDict #4396

Closed
not-my-profile opened this issue Jan 4, 2023 · 2 comments
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working

Comments

@not-my-profile
Copy link
Contributor

not-my-profile commented Jan 4, 2023

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:

@type_check_only
class _TypedDict(Mapping[str, object], metaclass=ABCMeta):
__total__: ClassVar[bool]
if sys.version_info >= (3, 9):
__required_keys__: ClassVar[frozenset[str]]
__optional_keys__: ClassVar[frozenset[str]]

(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 not-my-profile changed the title __required_keys__ and __opitonal_keys__ are not inherited from TypedDict __required_keys__ and __optional_keys__ are not inherited from TypedDict Jan 4, 2023
erictraut pushed a commit that referenced this issue Jan 4, 2023
…_required_keys__` and `__optional_keys__` class variables from a TypedDict class. This addresses #4396.
@erictraut
Copy link
Collaborator

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

@erictraut erictraut added bug Something isn't working addressed in next version Issue is fixed and will appear in next published version labels Jan 4, 2023
@erictraut
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants