ruff/crates/ty_python_semantic/resources/mdtest/dataclasses
Eric Jolibois 58efd19f11
[ty] apply `KW_ONLY` sentinel only to local fields (#19986)
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
2025-08-19 11:01:35 -07:00
..
dataclass_transform.md [ty] support `kw_only=True` for `dataclass()` and `field()` (#19677) 2025-08-14 08:02:55 -07:00
dataclasses.md [ty] apply `KW_ONLY` sentinel only to local fields (#19986) 2025-08-19 11:01:35 -07:00
fields.md [ty] support `kw_only=True` for `dataclass()` and `field()` (#19677) 2025-08-14 08:02:55 -07:00