@@ -2124,7 +2124,7 @@ else:
2124
2124
[builtins fixtures/dict.pyi]
2125
2125
[typing fixtures/typing-typeddict.pyi]
2126
2126
2127
- [case testOperatorContainsNarrowsTypedDicts_partial ]
2127
+ [case testOperatorContainsNarrowsTypedDicts_partialThroughTotalFalse ]
2128
2128
from __future__ import annotations
2129
2129
from typing import assert_type, Literal, TypedDict, Union
2130
2130
from typing_extensions import final
@@ -2160,6 +2160,38 @@ else:
2160
2160
[builtins fixtures/dict.pyi]
2161
2161
[typing fixtures/typing-typeddict.pyi]
2162
2162
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
+
2163
2195
[case testCannotSubclassFinalTypedDict]
2164
2196
from typing import TypedDict
2165
2197
from typing_extensions import final
0 commit comments