summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_typing.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_typing.py')
-rw-r--r--Lib/test/test_typing.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 6698031..4fbb410 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -7769,6 +7769,46 @@ class TypedDictTests(BaseTestCase):
'voice': str,
})
+ def test_keys_inheritance_with_same_name(self):
+ class NotTotal(TypedDict, total=False):
+ a: int
+
+ class Total(NotTotal):
+ a: int
+
+ self.assertEqual(NotTotal.__required_keys__, frozenset())
+ self.assertEqual(NotTotal.__optional_keys__, frozenset(['a']))
+ self.assertEqual(Total.__required_keys__, frozenset(['a']))
+ self.assertEqual(Total.__optional_keys__, frozenset())
+
+ class Base(TypedDict):
+ a: NotRequired[int]
+ b: Required[int]
+
+ class Child(Base):
+ a: Required[int]
+ b: NotRequired[int]
+
+ self.assertEqual(Base.__required_keys__, frozenset(['b']))
+ self.assertEqual(Base.__optional_keys__, frozenset(['a']))
+ self.assertEqual(Child.__required_keys__, frozenset(['a']))
+ self.assertEqual(Child.__optional_keys__, frozenset(['b']))
+
+ def test_multiple_inheritance_with_same_key(self):
+ class Base1(TypedDict):
+ a: NotRequired[int]
+
+ class Base2(TypedDict):
+ a: Required[str]
+
+ class Child(Base1, Base2):
+ pass
+
+ # Last base wins
+ self.assertEqual(Child.__annotations__, {'a': Required[str]})
+ self.assertEqual(Child.__required_keys__, frozenset(['a']))
+ self.assertEqual(Child.__optional_keys__, frozenset())
+
def test_required_notrequired_keys(self):
self.assertEqual(NontotalMovie.__required_keys__,
frozenset({"title"}))