Skip to content

Commit 808f593

Browse files
added unit test for 19902
1 parent 63224f2 commit 808f593

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test-data/unit/check-typeddict.test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,27 @@ def test_chaining(d: Config) -> None:
12131213
[typing fixtures/typing-typeddict.pyi]
12141214

12151215

1216+
[case testTypedDictGetWithNestedUnionOfTypedDicts]
1217+
# https://github.com/python/mypy/issues/19902
1218+
from typing import TypedDict, Union
1219+
from typing_extensions import TypeAlias, NotRequired
1220+
class A(TypedDict):
1221+
key: NotRequired[int]
1222+
1223+
class B(TypedDict):
1224+
key: NotRequired[int]
1225+
1226+
class C(TypedDict):
1227+
key: NotRequired[int]
1228+
1229+
A_or_B: TypeAlias = Union[A, B]
1230+
A_or_B_or_C: TypeAlias = Union[A_or_B, C]
1231+
1232+
def test(d: A_or_B_or_C) -> None:
1233+
reveal_type(d.get("key")) # N: Revealed type is "Union[builtins.int, None]"
1234+
[builtins fixtures/dict.pyi]
1235+
[typing fixtures/typing-typeddict.pyi]
1236+
12161237
-- Totality (the "total" keyword argument)
12171238

12181239
[case testTypedDictWithTotalTrue]

0 commit comments

Comments
 (0)