Skip to content

Commit

Permalink
Drop runtime error in PEP 705 implementation (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra authored Feb 14, 2024
1 parent ff530f5 commit d6c50f5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Unreleased

- Drop runtime error when a mutable `TypedDict` key overrides a read-only
one. Type checkers should still flag this as an error. Patch by Jelle
Zijlstra.
- Speedup `issubclass()` checks against simple runtime-checkable protocols by
around 6% (backporting https://github.com/python/cpython/pull/112717, by Alex
Waygood).
Expand Down
7 changes: 3 additions & 4 deletions src/test_typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4143,13 +4143,12 @@ class Child2(Base2):
self.assertEqual(Child1.__readonly_keys__, frozenset({'a'}))
self.assertEqual(Child1.__mutable_keys__, frozenset({'b'}))

def test_cannot_make_mutable_key_readonly(self):
def test_make_mutable_key_readonly(self):
class Base(TypedDict):
a: int

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

def test_can_make_readonly_key_mutable(self):
class Base(TypedDict):
Expand Down
5 changes: 0 additions & 5 deletions src/typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,11 +942,6 @@ def __new__(cls, name, bases, ns, *, total=True):
else:
optional_keys.add(annotation_key)
if ReadOnly in qualifiers:
if annotation_key in mutable_keys:
raise TypeError(
f"Cannot override mutable key {annotation_key!r}"
" with read-only key"
)
readonly_keys.add(annotation_key)
else:
mutable_keys.add(annotation_key)
Expand Down

0 comments on commit d6c50f5

Please sign in to comment.