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 |
Rewrite a dataclass to be easily understood by pylint |
Function | infer |
Inference tip for an Unknown node that was dynamically generated to represent a dataclass attribute. |
Function | infer |
Inference tip for dataclass field calls. |
Function | is |
Return True if a decorated node has a dataclass decorator applied. |
Constant | DATACLASS |
Undocumented |
Constant | DATACLASSES |
Undocumented |
Constant | DEFAULT |
Undocumented |
Constant | FIELD |
Undocumented |
Function | _check |
Return True if we should generate an __init__ method for node. |
Function | _generate |
Return an init method for a dataclass given the targets. |
Function | _get |
Yield the AnnAssign nodes of dataclass attributes for the node. |
Function | _get |
Return a the default value of a field call, and the corresponding keyword argument name. |
Function | _infer |
Infer an instance corresponding to the type annotation represented by node. |
Function | _is |
Return True if node is a ClassVar, with or without subscripting. |
Function | _is |
Return True if node is an InitVar, with or without subscripting. |
Function | _looks |
Return True if node was dynamically generated as the child of an AnnAssign statement. |
Function | _looks |
Return True if node looks like a dataclass decorator. |
Function | _looks |
Return True if node is calling dataclasses field or Field from an AnnAssign statement directly in the body of a ClassDef. |
Constant | _INFERABLE |
Undocumented |
Type Alias | _ |
Undocumented |
Unknown
, ctx: context.InferenceContext | None
= None) -> Generator
:
(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.
Call
, ctx: context.InferenceContext | None
= None) -> Generator
:
(source)
¶
Inference tip for dataclass field calls.
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
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.
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.
NodeNG
, ctx: context.InferenceContext | None
= None) -> Generator
:
(source)
¶
Infer an instance corresponding to the type annotation represented by node.
Currently has limited support for the typing module.
NodeNG
, decorator_names: frozenset[ str]
= DATACLASSES_DECORATORS) -> bool
:
(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.
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.