summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorVlad Emelianov <volshebnyi@gmail.com>2020-02-13 19:53:29 (GMT)
committerGitHub <noreply@github.com>2020-02-13 19:53:29 (GMT)
commit10e87e5ef4c1b4fb8415d9ddc362e2591f2f0b6c (patch)
treee8d12b75cb57405b029fb923c94d0c65169f41d9 /Lib/test
parentfbeba8f2481411d608a616366394e07cdc52e0bb (diff)
downloadcpython-10e87e5ef4c1b4fb8415d9ddc362e2591f2f0b6c.zip
cpython-10e87e5ef4c1b4fb8415d9ddc362e2591f2f0b6c.tar.gz
cpython-10e87e5ef4c1b4fb8415d9ddc362e2591f2f0b6c.tar.bz2
bpo-39627: Fix TypedDict totality check for inherited keys (#18503)
(Adapted from https://github.com/python/typing/pull/700)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_typing.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index bc6a3db..6b0a905 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -3809,6 +3809,38 @@ class TypedDictTests(BaseTestCase):
assert Point2Dor3D.__required_keys__ == frozenset(['x', 'y'])
assert Point2Dor3D.__optional_keys__ == frozenset(['z'])
+ def test_keys_inheritance(self):
+ class BaseAnimal(TypedDict):
+ name: str
+
+ class Animal(BaseAnimal, total=False):
+ voice: str
+ tail: bool
+
+ class Cat(Animal):
+ fur_color: str
+
+ assert BaseAnimal.__required_keys__ == frozenset(['name'])
+ assert BaseAnimal.__optional_keys__ == frozenset([])
+ assert BaseAnimal.__annotations__ == {'name': str}
+
+ assert Animal.__required_keys__ == frozenset(['name'])
+ assert Animal.__optional_keys__ == frozenset(['tail', 'voice'])
+ assert Animal.__annotations__ == {
+ 'name': str,
+ 'tail': bool,
+ 'voice': str,
+ }
+
+ assert Cat.__required_keys__ == frozenset(['name', 'fur_color'])
+ assert Cat.__optional_keys__ == frozenset(['tail', 'voice'])
+ assert Cat.__annotations__ == {
+ 'fur_color': str,
+ 'name': str,
+ 'tail': bool,
+ 'voice': str,
+ }
+
class IOTests(BaseTestCase):