Skip to content

Commit bf4364f

Browse files
committed
test totality through both total= and (Not)Required
1 parent f72a634 commit bf4364f

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

test-data/unit/check-typeddict.test

+33-1
Original file line numberDiff line numberDiff line change
@@ -2124,7 +2124,7 @@ else:
21242124
[builtins fixtures/dict.pyi]
21252125
[typing fixtures/typing-typeddict.pyi]
21262126

2127-
[case testOperatorContainsNarrowsTypedDicts_partial]
2127+
[case testOperatorContainsNarrowsTypedDicts_partialThroughTotalFalse]
21282128
from __future__ import annotations
21292129
from typing import assert_type, Literal, TypedDict, Union
21302130
from typing_extensions import final
@@ -2160,6 +2160,38 @@ else:
21602160
[builtins fixtures/dict.pyi]
21612161
[typing fixtures/typing-typeddict.pyi]
21622162

2163+
[case testOperatorContainsNarrowsTypedDicts_partialThroughNotRequired]
2164+
from __future__ import annotations
2165+
from typing import assert_type, Required, NotRequired, TypedDict, Union
2166+
from typing_extensions import final
2167+
2168+
@final
2169+
class D1(TypedDict):
2170+
required_key: Required[int]
2171+
optional_key: NotRequired[int]
2172+
2173+
2174+
@final
2175+
class D2(TypedDict):
2176+
abc: int
2177+
xyz: int
2178+
2179+
2180+
d: D1 | D2
2181+
2182+
if 'required_key' in d:
2183+
assert_type(d, D1)
2184+
else:
2185+
assert_type(d, D2)
2186+
2187+
if 'optional_key' in d:
2188+
assert_type(d, D1)
2189+
else:
2190+
assert_type(d, Union[D1, D2])
2191+
2192+
[builtins fixtures/dict.pyi]
2193+
[typing fixtures/typing-typeddict.pyi]
2194+
21632195
[case testCannotSubclassFinalTypedDict]
21642196
from typing import TypedDict
21652197
from typing_extensions import final

0 commit comments

Comments
 (0)