@@ -438,6 +438,15 @@ p = TaggedPoint(type='2d', x=42, y=1337)
438
438
reveal_type(p.get('type')) # E: Revealed type is 'Union[builtins.str, builtins.None]'
439
439
reveal_type(p.get('x')) # E: Revealed type is 'Union[builtins.int, builtins.None]'
440
440
reveal_type(p.get('y', 0)) # E: Revealed type is 'builtins.int'
441
+ reveal_type(p.get('y', 'hello')) # E: Revealed type is 'Union[builtins.int, builtins.str]'
442
+ reveal_type(p.get('y', {})) # E: Revealed type is 'Union[builtins.int, builtins.dict[builtins.None, builtins.None]]'
443
+ [builtins fixtures/dict.pyi]
444
+
445
+ [case testDefaultParameterStillTypeChecked]
446
+ from mypy_extensions import TypedDict
447
+ TaggedPoint = TypedDict('TaggedPoint', {'type': str, 'x': int, 'y': int})
448
+ p = TaggedPoint(type='2d', x=42, y=1337)
449
+ p.get('x', 1 + 'y') # E: Unsupported operand types for + ("int" and "str")
441
450
[builtins fixtures/dict.pyi]
442
451
443
452
[case testCannotGetMethodWithInvalidStringLiteralKey]
@@ -455,14 +464,22 @@ key = 'type'
455
464
reveal_type(p.get(key)) # E: Revealed type is 'builtins.object*'
456
465
[builtins fixtures/dict.pyi]
457
466
458
- [case testChainedGetMethodWithFallback ]
467
+ [case testChainedGetMethodWithDictFallback ]
459
468
from mypy_extensions import TypedDict
460
469
TaggedPoint = TypedDict('TaggedPoint', {'type': str, 'x': int, 'y': int})
461
470
PointSet = TypedDict('PointSet', {'first_point': TaggedPoint})
462
471
p = PointSet(first_point=TaggedPoint(type='2d', x=42, y=1337))
463
472
reveal_type(p.get('first_point', {}).get('x', 0)) # E: Revealed type is 'builtins.int'
464
473
[builtins fixtures/dict.pyi]
465
474
475
+ [case testChainedGetMethodWithNonDictFallback]
476
+ from mypy_extensions import TypedDict
477
+ TaggedPoint = TypedDict('TaggedPoint', {'type': str, 'x': int, 'y': int})
478
+ PointSet = TypedDict('PointSet', {'first_point': TaggedPoint})
479
+ p = PointSet(first_point=TaggedPoint(type='2d', x=42, y=1337))
480
+ p.get('first_point', 32).get('x', 0) # E: Some element of union has no attribute "get"
481
+ [builtins fixtures/dict.pyi]
482
+
466
483
[case testDictGetMethodStillCallable]
467
484
from typing import Callable
468
485
from mypy_extensions import TypedDict
0 commit comments