ruff
e5340724 - [ty] Preserve required stub fields in generated constructors (#27765)

Commit
17 hours ago
[ty] Preserve required stub fields in generated constructors (#27765) Annotation-only declarations in `.pyi` files act as bindings for attribute lookup, but they are not dataclass or `NamedTuple` field defaults. Previously, ty treated those synthetic bindings as defaults, making required constructor parameters optional and reporting false `dataclass-field-order` diagnostics when subclasses added required fields. Record whether an annotated assignment has a right-hand-side value in its semantic definition, and use that information when collecting generated fields from stubs. Only inline assignments, including `= ...`, count as stub-field defaults. Ordinary Python files and stub attribute lookup retain their existing behavior. Closes astral-sh/ty#4265. ## Test plan - Dataclass mdtests cover inherited required stub fields, constructor signatures and missing-argument diagnostics, explicit ellipsis defaults, and legitimate inherited field-order diagnostics. - Dataclass-transform mdtests cover inherited required stub-model fields, subclass constructor signatures, and missing arguments. - `NamedTuple` mdtests distinguish required annotation-only stub fields from explicit ellipsis defaults and verify constructor calls and missing-argument diagnostics.
Author
Parents
Loading