bpo-39627: Fix TypedDict totality check for inherited keys (#18503)

(Adapted from https://github.com/python/typing/pull/700)
This commit is contained in:
Vlad Emelianov 2020-02-13 20:53:29 +01:00 committed by GitHub
parent fbeba8f248
commit 10e87e5ef4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 13 deletions

View file

@ -3809,6 +3809,38 @@ class Point2Dor3D(Point2D, total=False):
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):