@@ -257,7 +257,77 @@ reveal_type(joined2) # E: Revealed type is 'builtins.list[builtins.object*]'
257
257
258
258
-- Meet
259
259
260
- -- TODO: Figure out some way to trigger the TypeMeetVisitor.visit_typeddict_type() path.
260
+ [case testMeetOfTypedDictsWithCompatibleCommonKeysHasAllKeysAndNewFallback]
261
+ from mypy_extensions import TypedDict
262
+ from typing import TypeVar, Callable
263
+ XY = TypedDict('XY', {'x': int, 'y': int})
264
+ YZ = TypedDict('YZ', {'y': int, 'z': int})
265
+ T = TypeVar('T')
266
+ def f(x: Callable[[T, T], None]) -> T: pass
267
+ def g(x: XY, y: YZ) -> None: pass
268
+ reveal_type(f(g)) # E: Revealed type is 'TypedDict(x=builtins.int, y=builtins.int, z=builtins.int, _fallback=typing.Mapping[builtins.str, builtins.int])'
269
+ [builtins fixtures/dict.pyi]
270
+
271
+ [case testMeetOfTypedDictsWithIncompatibleCommonKeysIsUninhabited]
272
+ # flags: --strict-optional
273
+ from mypy_extensions import TypedDict
274
+ from typing import TypeVar, Callable
275
+ XYa = TypedDict('XYa', {'x': int, 'y': int})
276
+ YbZ = TypedDict('YbZ', {'y': object, 'z': int})
277
+ T = TypeVar('T')
278
+ def f(x: Callable[[T, T], None]) -> T: pass
279
+ def g(x: XYa, y: YbZ) -> None: pass
280
+ reveal_type(f(g)) # E: Revealed type is '<uninhabited>'
281
+ [builtins fixtures/dict.pyi]
282
+
283
+ [case testMeetOfTypedDictsWithNoCommonKeysHasAllKeysAndNewFallback]
284
+ from mypy_extensions import TypedDict
285
+ from typing import TypeVar, Callable
286
+ X = TypedDict('X', {'x': int})
287
+ Z = TypedDict('Z', {'z': int})
288
+ T = TypeVar('T')
289
+ def f(x: Callable[[T, T], None]) -> T: pass
290
+ def g(x: X, y: Z) -> None: pass
291
+ reveal_type(f(g)) # E: Revealed type is 'TypedDict(x=builtins.int, z=builtins.int, _fallback=typing.Mapping[builtins.str, builtins.int])'
292
+ [builtins fixtures/dict.pyi]
293
+
294
+ # TODO: It would be more accurate for the meet to be TypedDict instead.
295
+ [case testMeetOfTypedDictWithCompatibleMappingIsUninhabitedForNow]
296
+ # flags: --strict-optional
297
+ from mypy_extensions import TypedDict
298
+ from typing import TypeVar, Callable, Mapping
299
+ X = TypedDict('X', {'x': int})
300
+ M = Mapping[str, int]
301
+ T = TypeVar('T')
302
+ def f(x: Callable[[T, T], None]) -> T: pass
303
+ def g(x: X, y: M) -> None: pass
304
+ reveal_type(f(g)) # E: Revealed type is '<uninhabited>'
305
+ [builtins fixtures/dict.pyi]
306
+
307
+ [case testMeetOfTypedDictWithIncompatibleMappingIsUninhabited]
308
+ # flags: --strict-optional
309
+ from mypy_extensions import TypedDict
310
+ from typing import TypeVar, Callable, Mapping
311
+ X = TypedDict('X', {'x': int})
312
+ M = Mapping[str, str]
313
+ T = TypeVar('T')
314
+ def f(x: Callable[[T, T], None]) -> T: pass
315
+ def g(x: X, y: M) -> None: pass
316
+ reveal_type(f(g)) # E: Revealed type is '<uninhabited>'
317
+ [builtins fixtures/dict.pyi]
318
+
319
+ # TODO: It would be more accurate for the meet to be TypedDict instead.
320
+ [case testMeetOfTypedDictWithCompatibleMappingSuperclassIsUninhabitedForNow]
321
+ # flags: --strict-optional
322
+ from mypy_extensions import TypedDict
323
+ from typing import TypeVar, Callable, Iterable
324
+ X = TypedDict('X', {'x': int})
325
+ I = Iterable[str]
326
+ T = TypeVar('T')
327
+ def f(x: Callable[[T, T], None]) -> T: pass
328
+ def g(x: X, y: I) -> None: pass
329
+ reveal_type(f(g)) # E: Revealed type is '<uninhabited>'
330
+ [builtins fixtures/dict.pyi]
261
331
262
332
263
333
-- Constraint Solver
0 commit comments