@@ -360,64 +360,56 @@ reveal_type(f(g)) # E: Revealed type is '<uninhabited>'
360
360
361
361
-- Special Method: __getitem__
362
362
363
- -- TODO: Implement support for this case.
364
- --[case testCanGetItemOfTypedDictWithValidStringLiteralKey]
365
- --from mypy_extensions import TypedDict
366
- --TaggedPoint = TypedDict('TaggedPoint ', {'type': str, 'x': int, 'y': int} )
367
- --p = TaggedPoint( type='2d', x=42, y=1337)
368
- --def get_x(p: TaggedPoint) -> int:
369
- -- return p['x']
370
- -- [builtins fixtures/dict.pyi]
363
+ [ case testCanGetItemOfTypedDictWithValidStringLiteralKey]
364
+ from mypy_extensions import TypedDict
365
+ TaggedPoint = TypedDict('TaggedPoint', {'type': str, 'x': int, 'y': int})
366
+ p = TaggedPoint(type='2d ', x=42, y=1337 )
367
+ reveal_type(p['type']) # E: Revealed type is 'builtins.str'
368
+ reveal_type(p['x']) # E: Revealed type is 'builtins. int'
369
+ reveal_type(p['y']) # E: Revealed type is 'builtins.int'
370
+ [builtins fixtures/dict.pyi]
371
371
372
- -- TODO: Implement support for this case.
373
- --[case testCannotGetItemOfTypedDictWithInvalidStringLiteralKey]
374
- --from mypy_extensions import TypedDict
375
- --TaggedPoint = TypedDict('TaggedPoint', {'type': str, 'x': int, 'y': int})
376
- --p = TaggedPoint(type='2d', x=42, y=1337)
377
- --def get_z(p: TaggedPoint) -> int:
378
- -- return p['z'] # E: ... 'z' is not a valid key for Point. Expected one of {'x', 'y'}.
379
- --[builtins fixtures/dict.pyi]
372
+ [case testCannotGetItemOfTypedDictWithInvalidStringLiteralKey]
373
+ from mypy_extensions import TypedDict
374
+ TaggedPoint = TypedDict('TaggedPoint', {'type': str, 'x': int, 'y': int})
375
+ p = TaggedPoint(type='2d', x=42, y=1337)
376
+ p['z'] # E: 'z' is not a valid item name. Expected one of ['type', 'x', 'y'].
377
+ [builtins fixtures/dict.pyi]
380
378
381
- -- TODO: Implement support for this case.
382
- --[case testCannotGetItemOfTypedDictWithNonLiteralKey]
383
- --from mypy_extensions import TypedDict
384
- --from typing import Union
385
- --TaggedPoint = TypedDict('TaggedPoint', {'type': str, 'x': int, 'y': int})
386
- --p = TaggedPoint(type='2d', x=42, y=1337)
387
- --def get_coordinate(p: TaggedPoint, key: str) -> Union[str, int]:
388
- -- return p[key] # E: ... Cannot prove 'key' is a valid key for Point. Expected one of {'x', 'y'}
389
- --[builtins fixtures/dict.pyi]
379
+ [case testCannotGetItemOfTypedDictWithNonLiteralKey]
380
+ from mypy_extensions import TypedDict
381
+ from typing import Union
382
+ TaggedPoint = TypedDict('TaggedPoint', {'type': str, 'x': int, 'y': int})
383
+ p = TaggedPoint(type='2d', x=42, y=1337)
384
+ def get_coordinate(p: TaggedPoint, key: str) -> Union[str, int]:
385
+ return p[key] # E: Cannot prove expression is a valid item name. Expected one of ['type', 'x', 'y'].
386
+ [builtins fixtures/dict.pyi]
390
387
391
388
392
389
-- Special Method: __setitem__
393
390
394
- -- TODO: Implement support for this case.
395
- --[case testCanSetItemOfTypedDictWithValidStringLiteralKey]
396
- --from mypy_extensions import TypedDict
397
- --TaggedPoint = TypedDict('TaggedPoint', {'type': str, 'x': int, 'y': int})
398
- --p = TaggedPoint(type='2d', x=42, y=1337)
399
- --def set_x(p: TaggedPoint, x: int) -> None:
400
- -- p['x'] = x
401
- --[builtins fixtures/dict.pyi]
391
+ [case testCanSetItemOfTypedDictWithValidStringLiteralKey]
392
+ from mypy_extensions import TypedDict
393
+ TaggedPoint = TypedDict('TaggedPoint', {'type': str, 'x': int, 'y': int})
394
+ p = TaggedPoint(type='2d', x=42, y=1337)
395
+ p['x'] = 1
396
+ [builtins fixtures/dict.pyi]
402
397
403
- -- TODO: Implement support for this case.
404
- --[case testCannotSetItemOfTypedDictWithInvalidStringLiteralKey]
405
- --from mypy_extensions import TypedDict
406
- --TaggedPoint = TypedDict('TaggedPoint', {'type': str, 'x': int, 'y': int})
407
- --p = TaggedPoint(type='2d', x=42, y=1337)
408
- --def set_z(p: TaggedPoint, z: int) -> None:
409
- -- p['z'] = z # E: ... 'z' is not a valid key for Point. Expected one of {'x', 'y'}.
410
- --[builtins fixtures/dict.pyi]
398
+ [case testCannotSetItemOfTypedDictWithInvalidStringLiteralKey]
399
+ from mypy_extensions import TypedDict
400
+ TaggedPoint = TypedDict('TaggedPoint', {'type': str, 'x': int, 'y': int})
401
+ p = TaggedPoint(type='2d', x=42, y=1337)
402
+ p['z'] = 1 # E: 'z' is not a valid item name. Expected one of ['type', 'x', 'y'].
403
+ [builtins fixtures/dict.pyi]
411
404
412
- -- TODO: Implement support for this case.
413
- --[case testCannotSetItemOfTypedDictWithNonLiteralKey]
414
- --from mypy_extensions import TypedDict
415
- --from typing import Union
416
- --TaggedPoint = TypedDict('TaggedPoint', {'type': str, 'x': int, 'y': int})
417
- --p = TaggedPoint(type='2d', x=42, y=1337)
418
- --def set_coordinate(p: TaggedPoint, key: str, value: Union[str, int]) -> None:
419
- -- p[key] = value # E: ... Cannot prove 'key' is a valid key for Point. Expected one of {'x', 'y'}
420
- --[builtins fixtures/dict.pyi]
405
+ [case testCannotSetItemOfTypedDictWithNonLiteralKey]
406
+ from mypy_extensions import TypedDict
407
+ from typing import Union
408
+ TaggedPoint = TypedDict('TaggedPoint', {'type': str, 'x': int, 'y': int})
409
+ p = TaggedPoint(type='2d', x=42, y=1337)
410
+ def set_coordinate(p: TaggedPoint, key: str, value: int) -> None:
411
+ p[key] = value # E: Cannot prove expression is a valid item name. Expected one of ['type', 'x', 'y'].
412
+ [builtins fixtures/dict.pyi]
421
413
422
414
423
415
-- Special Method: get
0 commit comments