[ty] Recognize __dataclass_transform__ to support SQLModel by rayzeller · Pull Request #23070 · astral-sh/ruff (original) (raw)
For backwards compatibility with pre-3.11 Python, ty now recognizes
any function named __dataclass_transform__ as equivalent to
typing.dataclass_transform, regardless of which module it is
defined in. This matches pyright's behavior and enables proper
type checking for libraries like SQLModel that use this pattern.
Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com
sharkdp marked this pull request as ready for review
This changes how we extract parameters from dataclass_transform() calls
from positional pattern matching to named parameter lookup. This allows
custom __dataclass_transform__ functions (like SQLModel's) with different
signatures to work correctly.
The previous code used if let [6 params] which silently failed for
functions with fewer parameters. Named lookup with defaults is more robust
and matches how Python interprets the keyword-only parameters.
Also adds a fallback from field_descriptors to field_specifiers for
SQLModel compatibility.
Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com
Multi-file analysis & type inference
label
sharkdp changed the title
[ty] Recognize [ty] Recognize __dataclass_transform__ as dataclass_transform__dataclass_transform__ to support SQLModel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})