Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
27 changes: 27 additions & 0 deletions src/test_typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4237,6 +4237,33 @@ def test_total(self):
self.assertEqual(Options.__required_keys__, frozenset())
self.assertEqual(Options.__optional_keys__, {'log_level', 'log_path'})

def test_total_inherits_non_total(self):
class TD1(TypedDict, total=False):
a: int

self.assertIs(TD1.__total__, False)

class TD2(TD1):
b: str

self.assertIs(TD2.__total__, True)

def test_total_with_assigned_value(self):
class TD(TypedDict):
__total__ = "some_value"

self.assertIs(TD.__total__, True)

class TD2(TypedDict, total=True):
__total__ = "some_value"

self.assertIs(TD2.__total__, True)

class TD3(TypedDict, total=False):
__total__ = "some value"

self.assertIs(TD3.__total__, False)

def test_optional_keys(self):
class Point2Dor3D(Point2D, total=False):
z: int
Expand Down
3 changes: 1 addition & 2 deletions src/typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,8 +1029,7 @@ def __new__(cls, name, bases, ns, *, total=True, closed=False):
tp_dict.__optional_keys__ = frozenset(optional_keys)
tp_dict.__readonly_keys__ = frozenset(readonly_keys)
tp_dict.__mutable_keys__ = frozenset(mutable_keys)
if not hasattr(tp_dict, '__total__'):
tp_dict.__total__ = total
tp_dict.__total__ = total
tp_dict.__closed__ = closed
tp_dict.__extra_items__ = extra_items_type
return tp_dict
Expand Down
Loading