Skip to content

[PEP 695] Fix covariance of frozen dataclasses#17783

Merged
JukkaL merged 1 commit into
masterfrom
variance-dataclass
Sep 18, 2024
Merged

[PEP 695] Fix covariance of frozen dataclasses#17783
JukkaL merged 1 commit into
masterfrom
variance-dataclass

Conversation

@JukkaL
Copy link
Copy Markdown
Collaborator

@JukkaL JukkaL commented Sep 18, 2024

Fix this conformance test:

@dataclass(frozen=True)
class ShouldBeCovariant4[T]:
    x: T

vo4_1: ShouldBeCovariant4[float] = ShouldBeCovariant4[int](1)  # OK
vo4_2: ShouldBeCovariant4[int] = ShouldBeCovariant4[float](1)  # E

Link:
https://github.com/python/typing/blob/main/conformance/tests/generics_variance_inference.py#L66

Fix this conformance test:
```
@DataClass(frozen=True)
class ShouldBeCovariant4[T]:
    x: T

vo4_1: ShouldBeCovariant4[float] = ShouldBeCovariant4[int](1)  # OK
vo4_2: ShouldBeCovariant4[int] = ShouldBeCovariant4[float](1)  # E
```
Link:
https://github.com/python/typing/blob/main/conformance/tests/generics_variance_inference.py#L66
@github-actions
Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@JukkaL JukkaL merged commit 9d7a042 into master Sep 18, 2024
@JukkaL JukkaL deleted the variance-dataclass branch September 18, 2024 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants