Skip to content

Commit adc8eea

Browse files
Aaron WieczorekAaron Wieczorek
authored andcommitted
test for fix: preserve specialization in generic TypedDict.update() plugin
1 parent b3c4bb3 commit adc8eea

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

test-data/unit/check-typeddict.test

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3011,6 +3011,39 @@ reveal_type(s3) # N: Revealed type is "TypedDict('__main__.Sub3', {'x': Any, 'y
30113011
[builtins fixtures/dict.pyi]
30123012
[typing fixtures/typing-typeddict.pyi]
30133013

3014+
[case testGenericTypedDictUpdate]
3015+
from typing import TypedDict, Generic, TypeVar
3016+
3017+
T = TypeVar("T")
3018+
3019+
class Group(TypedDict, Generic[T]):
3020+
a: T
3021+
3022+
value: Group[int] = {"a": 1}
3023+
3024+
def func(value2: Group[int]) -> None:
3025+
value.update(value2)
3026+
value.update({"a": 2})
3027+
value.update({"a": "string"}) # E: Incompatible types (expression has type "str", TypedDict item "a" has type "int")
3028+
3029+
S = TypeVar("S")
3030+
3031+
class MultiField(TypedDict, Generic[T, S]):
3032+
x: T
3033+
y: S
3034+
3035+
mf1: MultiField[int, str] = {"x": 1, "y": "a"}
3036+
mf2: MultiField[int, str] = {"x": 2, "y": "b"}
3037+
mf1.update(mf2)
3038+
3039+
mf3: MultiField[str, str] = {"x": "test", "y": "c"}
3040+
mf1.update(mf3) # E: Argument 1 to "update" of "TypedDict" has incompatible type "MultiField[str, str]"; expected "TypedDict({'x': int, 'y': str})"
3041+
3042+
mf1.update({"x": 3})
3043+
mf1.update({"y": "d"})
3044+
[builtins fixtures/dict.pyi]
3045+
[typing fixtures/typing-typeddict.pyi]
3046+
30143047
[case testTypedDictAttributeOnClassObject]
30153048
from typing import TypedDict
30163049

0 commit comments

Comments
 (0)