mirror of https://github.com/astral-sh/ruff
fix https://github.com/astral-sh/ty/issues/1047 ## Summary This PR fixes how `KW_ONLY` is applied in dataclasses. Previously, the sentinel leaked into subclasses and incorrectly marked their fields as keyword-only; now it only affects fields declared in the same class. ```py from dataclasses import dataclass, KW_ONLY @dataclass class D: x: int _: KW_ONLY y: str @dataclass class E(D): z: bytes # This should work: x=1 (positional), z=b"foo" (positional), y="foo" (keyword-only) E(1, b"foo", y="foo") reveal_type(E.__init__) # revealed: (self: E, x: int, z: bytes, *, y: str) -> None ``` <!-- What's the purpose of the change? What does it do, and why? --> ## Test Plan <!-- How was it tested? --> mdtests |
||
|---|---|---|
| .. | ||
| dataclass_transform.md | ||
| dataclasses.md | ||
| fields.md | ||