Skip to content

Python 3.13: TypedDict.__readonly_keys__ and __mutable_keys__ missing #18810

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

Closed
srittau opened this issue Mar 17, 2025 · 2 comments
Closed

Python 3.13: TypedDict.__readonly_keys__ and __mutable_keys__ missing #18810

srittau opened this issue Mar 17, 2025 · 2 comments
Labels
bug mypy got something wrong

Comments

@srittau
Copy link
Contributor

srittau commented Mar 17, 2025

Bug Report

Cf. python/typeshed#13638

mypy doesn't synthesize the __readonly_keys__ and __mutable_keys__ class attributes of TypedDict, introduced in Python 3.13. This leads to stubtest complaining about each instance of a TypedDict due to the attributes missing from the stubs.

To Reproduce

# foo.py

from typing import TypedDict

class Foo(TypedDict):
    bar: str
    
print(Foo.__readonly_keys__)  # at runtime: frozenset()
print(Foo.__mutable_keys__)  # at runtime: frozenset({'bar'})

Expected Behavior

Using mypy --python-version 3.13 foo.py: no errors.

Actual Behavior

foo.py:8: error: "type[Foo]" has no attribute "__readonly_keys__"  [attr-defined]
foo.py:9: error: "type[Foo]" has no attribute "__mutable_keys__"  [attr-defined]
Found 2 errors in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.15.0
  • Mypy command-line flags: --python-version 3.13
  • Mypy configuration options from mypy.ini (and other config files): ./.
  • Python version used: 3.12
@srittau srittau added the bug mypy got something wrong label Mar 17, 2025
srittau added a commit to srittau/typeshed that referenced this issue Mar 17, 2025
@AlexWaygood
Copy link
Member

Ah shoot, now that I look at this again, I think this is a typeshed bug? We should probably be listing these attributes in the typing._TypedDict stub here: https://github.com/python/typeshed/blob/205e993b52681f14fe38f3790f88e39e7cf3474b/stdlib/typing.pyi#L945-L952

same as we do in our stub for typing_extensions here: https://github.com/python/typeshed/blob/205e993b52681f14fe38f3790f88e39e7cf3474b/stdlib/typing_extensions.pyi#L225-L227

@srittau
Copy link
Contributor Author

srittau commented Mar 17, 2025

Good point, I'll send a PR. That will also make sure that it will work with any Python version.

@srittau srittau closed this as not planned Won't fix, can't repro, duplicate, stale Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants