module documentation
(source)

Astroid hook for the dataclasses library

Support built-in dataclasses, pydantic.dataclasses, and marshmallow_dataclass-annotated dataclasses. References: - https://docs.python.org/3/library/dataclasses.html - https://pydantic-docs.helpmanual.io/usage/dataclasses/ - https://lovasoa.github.io/marshmallow_dataclass/

Function dataclass​_transform Rewrite a dataclass to be easily understood by pylint
Function infer​_dataclass​_attribute Inference tip for an Unknown node that was dynamically generated to represent a dataclass attribute.
Function infer​_dataclass​_field​_call Inference tip for dataclass field calls.
Function is​_decorated​_with​_dataclass Return True if a decorated node has a dataclass decorator applied.
Constant DATACLASS​_MODULES Undocumented
Constant DATACLASSES​_DECORATORS Undocumented
Constant DEFAULT​_FACTORY Undocumented
Constant FIELD​_NAME Undocumented
Function _check​_generate​_dataclass​_init Return True if we should generate an __init__ method for node.
Function _generate​_dataclass​_init Return an init method for a dataclass given the targets.
Function _get​_dataclass​_attributes Yield the AnnAssign nodes of dataclass attributes for the node.
Function _get​_field​_default Return a the default value of a field call, and the corresponding keyword argument name.
Function _infer​_instance​_from​_annotation Infer an instance corresponding to the type annotation represented by node.
Function _is​_class​_var Return True if node is a ClassVar, with or without subscripting.
Function _is​_init​_var Return True if node is an InitVar, with or without subscripting.
Function _looks​_like​_dataclass​_attribute Return True if node was dynamically generated as the child of an AnnAssign statement.
Function _looks​_like​_dataclass​_decorator Return True if node looks like a dataclass decorator.
Function _looks​_like​_dataclass​_field​_call Return True if node is calling dataclasses field or Field from an AnnAssign statement directly in the body of a ClassDef.
Constant _INFERABLE​_TYPING​_TYPES Undocumented
Variable _​Field​Default​Return Undocumented
def dataclass_transform(node): (source)
Rewrite a dataclass to be easily understood by pylint
Parameters
node:ClassDefUndocumented
def infer_dataclass_attribute(node, ctx=None): (source)

Inference tip for an Unknown node that was dynamically generated to represent a dataclass attribute.

In the case that a default value is provided, that is inferred first. Then, an Instance of the annotated class is yielded.

Parameters
node:UnknownUndocumented
ctx:Optional[context.InferenceContext]Undocumented
Returns
GeneratorUndocumented
def infer_dataclass_field_call(node, ctx=None): (source)
Inference tip for dataclass field calls.
Parameters
node:CallUndocumented
ctx:Optional[context.InferenceContext]Undocumented
Returns
GeneratorUndocumented
def is_decorated_with_dataclass(node, decorator_names=DATACLASSES_DECORATORS): (source)
Return True if a decorated node has a dataclass decorator applied.
DATACLASS_MODULES = (source)

Undocumented

Value
frozenset(('dataclasses', 'marshmallow_dataclass', 'pydantic.dataclasses'))
DATACLASSES_DECORATORS = (source)

Undocumented

Value
frozenset(('dataclass'))
DEFAULT_FACTORY: str = (source)

Undocumented

Value
'_HAS_DEFAULT_FACTORY'
FIELD_NAME: str = (source)

Undocumented

Value
'field'
def _check_generate_dataclass_init(node): (source)

Return True if we should generate an __init__ method for node.

This is True when:
  • node doesn't define its own __init__ method
  • the dataclass decorator was called without the keyword argument init=False
Parameters
node:ClassDefUndocumented
Returns
boolUndocumented
def _generate_dataclass_init(assigns): (source)
Return an init method for a dataclass given the targets.
Parameters
assigns:List[AnnAssign]Undocumented
Returns
strUndocumented
def _get_dataclass_attributes(node, init=False): (source)

Yield the AnnAssign nodes of dataclass attributes for the node.

If init is True, also include InitVars, but exclude attributes from calls to field where init=False.

Parameters
node:ClassDefUndocumented
init:boolUndocumented
Returns
GeneratorUndocumented
def _get_field_default(field_call): (source)

Return a the default value of a field call, and the corresponding keyword argument name.

field(default=...) results in the ... node field(default_factory=...) results in a Call node with func ... and no arguments

If neither or both arguments are present, return ("", None) instead, indicating that there is not a valid default value.

Parameters
field​_call:CallUndocumented
Returns
_FieldDefaultReturnUndocumented
def _infer_instance_from_annotation(node, ctx=None): (source)

Infer an instance corresponding to the type annotation represented by node.

Currently has limited support for the typing module.

Parameters
node:NodeNGUndocumented
ctx:Optional[context.InferenceContext]Undocumented
Returns
GeneratorUndocumented
def _is_class_var(node): (source)
Return True if node is a ClassVar, with or without subscripting.
Parameters
node:NodeNGUndocumented
Returns
boolUndocumented
def _is_init_var(node): (source)
Return True if node is an InitVar, with or without subscripting.
Parameters
node:NodeNGUndocumented
Returns
boolUndocumented
def _looks_like_dataclass_attribute(node): (source)
Return True if node was dynamically generated as the child of an AnnAssign statement.
Parameters
node:UnknownUndocumented
Returns
boolUndocumented
def _looks_like_dataclass_decorator(node, decorator_names=DATACLASSES_DECORATORS): (source)

Return True if node looks like a dataclass decorator.

Uses inference to lookup the value of the node, and if that fails, matches against specific names.

Parameters
node:NodeNGUndocumented
decorator​_names:FrozenSet[str]Undocumented
Returns
boolUndocumented
def _looks_like_dataclass_field_call(node, check_scope=True): (source)

Return True if node is calling dataclasses field or Field from an AnnAssign statement directly in the body of a ClassDef.

If check_scope is False, skips checking the statement and body.

Parameters
node:CallUndocumented
check​_scope:boolUndocumented
Returns
boolUndocumented
_INFERABLE_TYPING_TYPES = (source)

Undocumented

Value
frozenset(('Dict', 'FrozenSet', 'List', 'Set', 'Tuple'))
_FieldDefaultReturn = (source)

Undocumented