Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 33 additions & 0 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4892,6 +4892,18 @@ class NontotalMovie(TypedDict, total=False):
title: Required[str]
year: int

class ParentNontotalMovie(TypedDict, total=False):
title: Required[str]

class ChildTotalMovie(ParentNontotalMovie):
year: NotRequired[int]

class ParentDeeplyAnnotatedMovie(TypedDict):
title: Annotated[Annotated[Required[str], "foobar"], "another level"]

class ChildDeeplyAnnotatedMovie(ParentDeeplyAnnotatedMovie):
year: NotRequired[Annotated[int, 2000]]

class AnnotatedMovie(TypedDict):
title: Annotated[Required[str], "foobar"]
year: NotRequired[Annotated[int, 2000]]
Expand Down Expand Up @@ -5221,6 +5233,17 @@ def test_get_type_hints_typeddict(self):
'a': Annotated[Required[int], "a", "b", "c"]
})

self.assertEqual(get_type_hints(ChildTotalMovie), {"title": str, "year": int})
self.assertEqual(get_type_hints(ChildTotalMovie, include_extras=True), {
"title": Required[str], "year": NotRequired[int]
})

self.assertEqual(get_type_hints(ChildDeeplyAnnotatedMovie), {"title": str, "year": int})
self.assertEqual(get_type_hints(ChildDeeplyAnnotatedMovie, include_extras=True), {
"title": Annotated[Required[str], "foobar", "another level"],
"year": NotRequired[Annotated[int, 2000]]
})

def test_get_type_hints_collections_abc_callable(self):
# https://github.com/python/cpython/issues/91621
P = ParamSpec('P')
Expand Down Expand Up @@ -6381,6 +6404,16 @@ def test_required_notrequired_keys(self):
self.assertEqual(WeirdlyQuotedMovie.__optional_keys__,
frozenset({"year"}))

self.assertEqual(ChildTotalMovie.__required_keys__,
frozenset({"title"}))
self.assertEqual(ChildTotalMovie.__optional_keys__,
frozenset({"year"}))

self.assertEqual(ChildDeeplyAnnotatedMovie.__required_keys__,
frozenset({"title"}))
self.assertEqual(ChildDeeplyAnnotatedMovie.__optional_keys__,
frozenset({"year"}))

def test_multiple_inheritance(self):
class One(TypedDict):
one: int
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,7 @@ Jean-François Piéronne
Oleg Plakhotnyuk
Anatoliy Platonov
Marcel Plch
Kirill Podoprigora
Remi Pointel
Jon Poler
Ariel Poliak
Expand Down