Skip to content

Commit

Permalink
Fix changelog entry and __mutable_keys__ tracking for PEP 705 (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra authored Feb 16, 2024
1 parent 566e01e commit 9f040ab
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

- Add support for PEP 742, adding `typing_extensions.TypeIs`. Patch
by Jelle Zijlstra.
- Drop runtime error when a mutable `TypedDict` key overrides a read-only
- Drop runtime error when a read-only `TypedDict` item overrides a mutable
one. Type checkers should still flag this as an error. Patch by Jelle
Zijlstra.
- Speedup `issubclass()` checks against simple runtime-checkable protocols by
Expand Down
6 changes: 6 additions & 0 deletions src/test_typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4147,9 +4147,15 @@ def test_make_mutable_key_readonly(self):
class Base(TypedDict):
a: int

self.assertEqual(Base.__readonly_keys__, frozenset())
self.assertEqual(Base.__mutable_keys__, frozenset({'a'}))

class Child(Base):
a: ReadOnly[int] # type checker error, but allowed at runtime

self.assertEqual(Child.__readonly_keys__, frozenset({'a'}))
self.assertEqual(Child.__mutable_keys__, frozenset())

def test_can_make_readonly_key_mutable(self):
class Base(TypedDict):
a: ReadOnly[int]
Expand Down
1 change: 1 addition & 0 deletions src/typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,7 @@ def __new__(cls, name, bases, ns, *, total=True):
else:
optional_keys.add(annotation_key)
if ReadOnly in qualifiers:
mutable_keys.discard(annotation_key)
readonly_keys.add(annotation_key)
else:
mutable_keys.add(annotation_key)
Expand Down

0 comments on commit 9f040ab

Please sign in to comment.