[ty] Respect third-party keyword-only fields before Python 3.10 - #27699
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 96.98%. The percentage of expected errors that received a diagnostic held steady at 93.62%. The number of fully passing files held steady at 106/133. |
Memory usage reportMemory usage unchanged ✅ |
|
Merging this PR will not alter performance
Comparing Footnotes
|
carljm
left a comment
There was a problem hiding this comment.
Looks good! We could consider an actual-attrs integration test, but I don't think it's necessary, assuming you validated this does actually fix the OP case with attrs under Python 3.9.
|
Codex observes that we actually don't currently have any test using |
…al-sh#27699) ## Summary Previously, we ignored `kw_only=True` on every dataclass field specifier when targeting Python 3.9, even though libraries such as `attrs` support keyword-only fields independently of the standard library: ```python import attr @attr.s(auto_attribs=True) class Base: optional: float = attr.ib(default=1.0, kw_only=True) @attr.s(auto_attribs=True) class Child(Base): required: str ``` We now restrict the Python 3.10 requirement to `dataclasses.field`, preserving keyword-only behavior for third-party field specifiers on earlier Python versions. Inherited keyword-only fields no longer trigger `dataclass-field-order`, and synthesized constructors retain the correct argument ordering. Closes astral-sh/ty#4242.
Summary
Previously, we ignored
kw_only=Trueon every dataclass field specifier when targeting Python 3.9, even though libraries such asattrssupport keyword-only fields independently of the standard library:We now restrict the Python 3.10 requirement to
dataclasses.field, preserving keyword-only behavior for third-party field specifiers on earlier Python versions. Inherited keyword-only fields no longer triggerdataclass-field-order, and synthesized constructors retain the correct argument ordering.Closes astral-sh/ty#4242.