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
Move frozen-dataclass PEP 695 variance test to check-python313.test
The test exercises __replace__ synthesis, which the dataclass plugin only
generates on Python 3.13+. check-python313.test defaults to python_version
(3, 13) via testfile_pyversion; the explicit # flags: --python-version 3.13
pragma is therefore redundant and has been dropped, consistent with all
other tests in that file.
Assistant-Model: Claude Code
# On Python 3.13+ the dataclass plugin synthesizes a __replace__ method whose
254
-
# keyword parameters reuse the field types. Being plugin-generated, it must not
255
-
# drag the type variable into a contravariant position and make an otherwise
256
-
# covariant frozen dataclass invariant.
257
-
from dataclasses import dataclass
258
-
259
-
@dataclass(frozen=True)
260
-
class Covariant[T]:
261
-
x: T
262
-
263
-
cov1: Covariant[float] = Covariant[int](1)
264
-
cov2: Covariant[int] = Covariant[float](1) # E: Incompatible types in assignment (expression has type "Covariant[float]", variable has type "Covariant[int]")
Copy file name to clipboardExpand all lines: test-data/unit/check-python313.test
+16Lines changed: 16 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -480,3 +480,19 @@ reveal_type(x) # N: Revealed type is "builtins.list[tuple[()]]"
480
480
reveal_type(y) # N: Revealed type is "builtins.list[tuple[()]]"
481
481
reveal_type(z) # N: Revealed type is "builtins.list[tuple[()]]"
482
482
[builtins fixtures/tuple.pyi]
483
+
484
+
[case testPEP695InferVarianceInFrozenDataclass]
485
+
# On Python 3.13+ the dataclass plugin synthesizes a __replace__ method whose
486
+
# keyword parameters reuse the field types. Being plugin-generated, it must not
487
+
# drag the type variable into a contravariant position and make an otherwise
488
+
# covariant frozen dataclass invariant.
489
+
from dataclasses import dataclass
490
+
491
+
@dataclass(frozen=True)
492
+
class Covariant[T]:
493
+
x: T
494
+
495
+
cov1: Covariant[float] = Covariant[int](1)
496
+
cov2: Covariant[int] = Covariant[float](1) # E: Incompatible types in assignment (expression has type "Covariant[float]", variable has type "Covariant[int]")
0 commit comments