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 | _find |
Iterate through all bases and get their typing and defaults. |
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 | _get |
Get the default value of a previously defined field. |
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 | _is |
Return True if node is the KW_ONLY sentinel. |
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. |
Function | _parse |
Parse positional and keyword arguments into strings for an __init__ method. |
Constant | _INFERABLE |
Undocumented |
Type Alias | _ |
Undocumented |
nodes.Unknown
, ctx: context.InferenceContext|None
= None) -> Iterator[ InferenceResult]
:
(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.
nodes.Call
, ctx: context.InferenceContext|None
= None) -> Iterator[ InferenceResult]
:
(source)
¶
Inference tip for dataclass field calls.
nodes.ClassDef
, decorator_names: frozenset[ str]
= DATACLASSES_DECORATORS) -> bool
:
(source)
¶
Return True if a decorated node has a `dataclass` decorator applied.
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
nodes.ClassDef
) -> tuple[ dict[ str, tuple[ str|None, str|None]], dict[ str, tuple[ str|None, str|None]]]
:
(source)
¶
Iterate through all bases and get their typing and defaults.
nodes.ClassDef
, assigns: list[ nodes.AnnAssign]
, kw_only_decorated: bool
) -> str
:
(source)
¶
Return an init method for a dataclass given the targets.
nodes.ClassDef
, init: bool
= False) -> Iterator[ nodes.AnnAssign]
:
(source)
¶
Yield the AnnAssign nodes of dataclass attributes for the node. If init is True, also include InitVars.
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.
nodes.NodeNG
, ctx: context.InferenceContext|None
= None) -> Iterator[ UninferableBase|bases.Instance]
:
(source)
¶
Infer an instance corresponding to the type annotation represented by node. Currently has limited support for the typing module.
nodes.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.
nodes.Call
, check_scope: bool
= True) -> bool
:
(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.
dict[ str, tuple[ str|None, str|None]]
, kw_only_store: dict[ str, tuple[ str|None, str|None]]
) -> tuple[ str, str]
:
(source)
¶
Parse positional and keyword arguments into strings for an __init__ method.
Undocumented
Value |
|