You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[dataclass_transform] support subclass/metaclass-based transforms (#14657)
Support dataclass_transforms that use inheritance or metaclasses rather
than decorators. This only needs plumbing changes so that we can get the
correct metadata for a given class and trigger the dataclasses transform
plugin; logic should otherwise remain the same.
The code changes here are a little invasive because of how the
dataclasses plugin handles it's "reason" (ie, the AST node that
triggered the plugin). Currently it takes a `ClassDefContext` where
`reason: Expression`, but in the case of inheritance/metaclass-based
transforms, it makes more sense for the class definition itself to be
the reason (since the parent class and keyword args are supplied in the
class definition itself). To accommodate for this, I refactored the
`DataclassTransformer` class to take a `reason: Expression | Statement`
while leaving the plugin API itself alone. This mostly involved updating
the identifiers used throughout the class.
0 commit comments