You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
_ = replace(a_or_b, x=42, y=True, w={}, init_var=42) # E: Argument "w" to "replace" of "Union[A[int], B]" has incompatible type "Dict[<nothing>, <nothing>]"; expected <nothing>
2136
2138
_ = replace(a_or_b, y=42, init_var=42) # E: Argument "y" to "replace" of "Union[A[int], B]" has incompatible type "int"; expected "bool"
2137
2139
2138
-
[builtins fixtures/dataclasses.pyi]
2140
+
[builtins fixtures/tuple.pyi]
2139
2141
2140
2142
[case testReplaceUnionOfTypeVar]
2141
2143
from typing import Generic, Union, TypeVar
@@ -2155,7 +2157,9 @@ TA = TypeVar('TA', bound=A)
2155
2157
TB = TypeVar('TB', bound=B)
2156
2158
2157
2159
def f(b_or_t: Union[TA, TB, int]) -> None:
2158
-
a2 = replace(b_or_t) # E: Argument 1 to "replace" has type "Union[TA, TB, int]" whose item "TB" is not bound to a dataclass # E: Argument 1 to "replace" has incompatible type "Union[TA, TB, int]" whose item "int" is not a dataclass
2160
+
a2 = replace(b_or_t) # E: Value of type variable "_DataclassT" of "replace" cannot be "Union[TA, TB, int]"
_ = replace(t, x=42) # E: Argument 1 to "replace" has a variable type "TInt" not bound to a dataclass
2174
+
_ = replace(t, x=42) # E: Value of type variable "_DataclassT" of "replace" cannot be "TInt"
2171
2175
2172
2176
def f2(t: TAny) -> TAny:
2173
-
return replace(t, x='spam') # E: Argument 1 to "replace" has a variable type "TAny" not bound to a dataclass
2177
+
return replace(t, x='spam') # E: Value of type variable "_DataclassT" of "replace" cannot be "TAny"
2174
2178
2175
2179
def f3(t: TNone) -> TNone:
2176
-
return replace(t, x='spam') # E: Argument 1 to "replace" has a variable type "TNone" not bound to a dataclass
2180
+
return replace(t, x='spam') # E: Value of type variable "_DataclassT" of "replace" cannot be "TNone"
2177
2181
2178
2182
def f4(t: TUnion) -> TUnion:
2179
-
return replace(t, x='spam') # E: Argument 1 to "replace" has incompatible type "TUnion" whose item "str" is not a dataclass # E: Argument 1 to "replace" has incompatible type "TUnion" whose item "int" is not a dataclass
2183
+
return replace(t, x='spam') # E: Value of type variable "_DataclassT" of "replace" cannot be "TUnion"
2184
+
2185
+
[builtins fixtures/tuple.pyi]
2180
2186
2181
2187
[case testReplaceTypeVarBound]
2182
2188
from dataclasses import dataclass, replace
@@ -2201,6 +2207,8 @@ def f(t: TA) -> TA:
2201
2207
f(A(x=42))
2202
2208
f(B(x=42))
2203
2209
2210
+
[builtins fixtures/tuple.pyi]
2211
+
2204
2212
[case testReplaceAny]
2205
2213
from dataclasses import replace
2206
2214
from typing import Any
@@ -2209,17 +2217,30 @@ a: Any
2209
2217
a2 = replace(a)
2210
2218
reveal_type(a2) # N: Revealed type is "Any"
2211
2219
2220
+
[builtins fixtures/tuple.pyi]
2221
+
2212
2222
[case testReplaceNotDataclass]
2213
2223
from dataclasses import replace
2214
2224
2215
-
replace(5) # E: Argument 1 to "replace" has incompatible type "int"; expected a dataclass
2225
+
replace(5) # E: Value of type variable "_DataclassT" of "replace" cannot be "int"
2216
2226
2217
2227
class C:
2218
2228
pass
2219
2229
2220
-
replace(C()) # E: Argument 1 to "replace" has incompatible type "C"; expected a dataclass
2230
+
replace(C()) # E: Value of type variable "_DataclassT" of "replace" cannot be "C"
2221
2231
2222
-
replace(None) # E: Argument 1 to "replace" has incompatible type "None"; expected a dataclass
2232
+
replace(None) # E: Value of type variable "_DataclassT" of "replace" cannot be "None"
2233
+
2234
+
[builtins fixtures/tuple.pyi]
2235
+
2236
+
[case testReplaceIsDataclass]
2237
+
from dataclasses import is_dataclass, replace
2238
+
2239
+
def f(x: object) -> None:
2240
+
if is_dataclass(x) and not isinstance(x, type):
2241
+
y = replace(x)
2242
+
2243
+
[builtins fixtures/tuple.pyi]
2223
2244
2224
2245
[case testReplaceGeneric]
2225
2246
from dataclasses import dataclass, replace, InitVar
@@ -2238,6 +2259,8 @@ reveal_type(a2) # N: Revealed type is "__main__.A[builtins.int]"
2238
2259
a2 = replace(a, x='42') # E: Argument "x" to "replace" of "A[int]" has incompatible type "str"; expected "int"
2239
2260
reveal_type(a2) # N: Revealed type is "__main__.A[builtins.int]"
2240
2261
2262
+
[builtins fixtures/tuple.pyi]
2263
+
2241
2264
[case testPostInitCorrectSignature]
2242
2265
from typing import Any, Generic, TypeVar, Callable, Self
0 commit comments