Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Remove conflicting keys delete, it is not allowed to redefine TypedDi…
…ct keys
  • Loading branch information
vemel committed Feb 11, 2020
commit 4d89d78d8e15efca44ebb9464d8692f580d7f36f
19 changes: 9 additions & 10 deletions typing_extensions/src_py3/test_typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,16 +437,15 @@ class Options(TypedDict, total=False):
log_level: int
log_path: str

class _Animal(TypedDict):
class BaseAnimal(TypedDict):
name: str

class Animal(_Animal, total=False):
class Animal(BaseAnimal, total=False):
voice: str
tail: bool

class Cat(Animal):
fur_color: str
tail: int
"""

if PY36:
Expand All @@ -457,7 +456,7 @@ class Cat(Animal):
A = B = CSub = G = CoolEmployee = CoolEmployeeWithDefault = object
XMeth = XRepr = HasCallProtocol = NoneAndForward = Loop = object
Point2D = Point2Dor3D = LabelPoint2D = Options = object
_Animal = Animal = Cat = object
BaseAnimal = Animal = Cat = object

gth = get_type_hints

Expand Down Expand Up @@ -1565,9 +1564,9 @@ def test_optional_keys(self):

@skipUnless(PY36, 'Python 3.6 required')
def test_keys_inheritance(self):
assert _Animal.__required_keys__ == frozenset(['name'])
assert _Animal.__optional_keys__ == frozenset([])
assert _Animal.__annotations__ == {'name': 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'])
Expand All @@ -1577,12 +1576,12 @@ def test_keys_inheritance(self):
'voice': str,
}

assert Cat.__required_keys__ == frozenset(['name', 'fur_color', 'tail'])
assert Cat.__optional_keys__ == frozenset(['voice'])
assert Cat.__required_keys__ == frozenset(['name', 'fur_color'])
assert Cat.__optional_keys__ == frozenset(['tail', 'voice'])
assert Cat.__annotations__ == {
'fur_color': str,
'name': str,
'tail': int,
'tail': bool,
'voice': str,
}

Expand Down
2 changes: 0 additions & 2 deletions typing_extensions/src_py3/typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1669,10 +1669,8 @@ def __new__(cls, name, bases, ns, total=True):
annotations.update(own_annotations)
if total:
required_keys.update(own_annotation_keys)
optional_keys.difference_update(own_annotation_keys)
else:
optional_keys.update(own_annotation_keys)
required_keys.difference_update(own_annotation_keys)

tp_dict.__annotations__ = annotations
tp_dict.__required_keys__ = frozenset(required_keys)
Expand Down