Skip to content

Python 3.13: TypedDict.__readonly_keys__ and __mutable_keys__ missing #18810

Closed as not planned
@srittau

Description

@srittau

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions