class documentation

class DataclassTransformer: (source)

View In Hierarchy

Undocumented

Method __init__ Undocumented
Method add​_slots Undocumented
Method collect​_attributes Collect all attributes declared in the dataclass and its parents.
Method reset​_init​_only​_vars 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​_dataclass​_fields​_magic​_attribute Undocumented
Method _freeze Converts all attributes to @property methods in order to emulate frozen classes.
Method _is​_kw​_only​_type Checks if the type of the node is the KW_ONLY sentinel value.
Method _propertize​_callables Converts all attributes with callable types to @property methods.
Instance Variable _ctx Undocumented
def __init__(self, ctx): (source)

Undocumented

Parameters
ctx:ClassDefContextUndocumented
def add_slots(self, info, attributes, *, correct_version): (source)

Undocumented

Parameters
info:TypeInfoUndocumented
attributes:List[DataclassAttribute]Undocumented
correct​_version:boolUndocumented
def collect_attributes(self): (source)

Collect all attributes declared in the dataclass and its parents.

All assignments of the form

a: SomeType b: SomeOtherType = ...

are collected.

Returns
Optional[List[DataclassAttribute]]Undocumented
def reset_init_only_vars(self, info, attributes): (source)
Remove init-only vars from the class and reset init var declarations.
Parameters
info:TypeInfoUndocumented
attributes:List[DataclassAttribute]Undocumented
def transform(self): (source)
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.
def _add_dataclass_fields_magic_attribute(self): (source)

Undocumented

def _freeze(self, attributes): (source)
Converts all attributes to @property methods in order to emulate frozen classes.
Parameters
attributes:List[DataclassAttribute]Undocumented
def _is_kw_only_type(self, node): (source)
Checks if the type of the node is the KW_ONLY sentinel value.
Parameters
node:Optional[Type]Undocumented
Returns
boolUndocumented
def _propertize_callables(self, attributes): (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).

Parameters
attributes:List[DataclassAttribute]Undocumented
_ctx = (source)

Undocumented