class DataclassTransformer: (source)
Implement the behavior of @dataclass. Note that this may be executed multiple times on the same class, so everything here must be idempotent. This runs after the main semantic analysis pass, so you can assume that there are no placeholders.
Method | __init__ |
Undocumented |
Method | add |
Undocumented |
Method | collect |
Collect all attributes declared in the dataclass and its parents. |
Method | reset |
Remove init-only vars from the class and reset init var declarations. |
Method | transform |
Apply all the necessary transformations to the underlying dataclass so as to ensure it is fully type checked according to the rules in PEP 557. |
Method | _add |
Undocumented |
Method | _collect |
Returns a tuple where the first value represents whether or not the expression is a call to dataclass.field and the second is a dictionary of the keyword arguments that field() was called with. |
Method | _freeze |
Converts all attributes to @property methods in order to emulate frozen classes. |
Method | _get |
Undocumented |
Method | _is |
Checks if the type of the node is the KW_ONLY sentinel value. |
Method | _propertize |
Converts all attributes with callable types to @property methods. |
Instance Variable | _api |
Undocumented |
Instance Variable | _cls |
Undocumented |
Instance Variable | _reason |
Undocumented |
Instance Variable | _spec |
Undocumented |
ClassDef
, reason: Expression|Statement
, spec: DataclassTransformSpec
, api: SemanticAnalyzerPluginInterface
):
(source)
¶
Undocumented
TypeInfo
, attributes: list[ DataclassAttribute]
, *, correct_version: bool
):
(source)
¶
Undocumented
Collect all attributes declared in the dataclass and its parents. All assignments of the form a: SomeType b: SomeOtherType = ... are collected. Return None if some dataclass base class hasn't been processed yet and thus we'll need to ask for another pass.
Apply all the necessary transformations to the underlying dataclass so as to ensure it is fully type checked according to the rules in PEP 557.
Returns a tuple where the first value represents whether or not the expression is a call to dataclass.field and the second is a dictionary of the keyword arguments that field() was called with.
list[ DataclassAttribute]
, settable: bool
= True):
(source)
¶
Converts all attributes with callable types to @property methods. This avoids the typechecker getting confused and thinking that `my_dataclass_instance.callable_attr(foo)` is going to receive a `self` argument (it is not).