ty icon indicating copy to clipboard operation
ty copied to clipboard

Consolidate handling of dataclass-params and dataclass-transformer-params

Open sharkdp opened this issue 1 month ago • 2 comments

The goal of this ticket is to consolidate and clean up our handling of dataclass-params and dataclass-transformer-params for all different kinds of dataclasses: "standard" dataclasses.dataclass dataclasses, decorator-based dataclass transformers, base-class-based dataclass transformers, and metaclass-based dataclass transformers.

For more context, see this comment. In particular, this part:

I think we never properly added support for default_* params on base-class and metaclass-based transformers, but some contributors added partial support when synthesizing init. Instead of that partial support, we should either have generalized methods for querying dataclass params (from anywhere) which always fall back to the dataclass-transformer-params, or we should ensure that dataclass_params on the class itself are always already initialized with values from the transformer param defaults. (It looks like this currently happens for function dataclass transforms but not for metaclass or base-class ones.) It also looks like we store dataclass_transformer_params on the class, but this also isn't currently set for metaclass or base-class transformers. So this special-cased support for base-class and metaclass transformers that was added to init synthesis ought to be generalized, and if that happened this PR wouldn't need to explicitly check the transformer params.

sharkdp avatar Dec 10 '25 09:12 sharkdp

For more context, see also this discussion: https://github.com/astral-sh/ruff/pull/22018/files#r2630663471

sharkdp avatar Dec 18 '25 11:12 sharkdp