Skip to content

Python 3.13: TypedDict.__readonly_keys__ and __mutable_keys__ missing #18810

Closed as not planned

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

Activity

  1. added a commit that references this issue on Mar 17, 2025
  2. AlexWaygood commented on Mar 17, 2025

    @AlexWaygood
    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

  3. srittau commented on Mar 17, 2025

    @srittau
    ContributorAuthor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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