Skip to content

Commit 74e2000

Browse files
committed
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
1 parent 27410c5 commit 74e2000

2 files changed

Lines changed: 16 additions & 17 deletions

File tree

test-data/unit/check-python312.test

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -248,23 +248,6 @@ inv2: Invariant[int] = Invariant[float]([1]) # E: Incompatible types in assignm
248248
[builtins fixtures/tuple.pyi]
249249
[typing fixtures/typing-full.pyi]
250250

251-
[case testPEP695InferVarianceInFrozenDataclassPython313]
252-
# flags: --python-version 3.13
253-
# 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]")
265-
[builtins fixtures/tuple.pyi]
266-
[typing fixtures/typing-full.pyi]
267-
268251
[case testPEP695InferVarianceWithAttrsFrozen]
269252
import attrs
270253

test-data/unit/check-python313.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,3 +480,19 @@ reveal_type(x) # N: Revealed type is "builtins.list[tuple[()]]"
480480
reveal_type(y) # N: Revealed type is "builtins.list[tuple[()]]"
481481
reveal_type(z) # N: Revealed type is "builtins.list[tuple[()]]"
482482
[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]")
497+
[builtins fixtures/tuple.pyi]
498+
[typing fixtures/typing-full.pyi]

0 commit comments

Comments
 (0)