- class astroid.nodes.LocalsDictNodeNG(lineno: int | None, col_offset: int | None, parent: NodeNG | None, *, end_lineno: int | None, end_col_offset: int | None)#
this class provides locals handling common to Module, FunctionDef and ClassDef nodes, including a dict like interface for direct access to locals information
- add_local_node(child_node: nodes.ClassDef, name: str | None = None) None #
- add_local_node(child_node: nodes.NodeNG, name: str) None
Append a child that should alter the locals of this scope node.
child_node – The child node that will alter locals.
name – The name of the local that will be altered by the given child node.
Get the names of the locals and the node that defines the local.
The names of locals defined in this scoped node.
- locals: dict[str, list[InferenceResult]]#
A map of the name of a local variable to the node defining the local.
- qname() str #
Get the ‘qualified’ name of the node.
For example: module.name, module.class.name …
The qualified name.
- Return type:
- scope() _T #
The first parent node defining a new scope.
- scope_lookup(node: _base_nodes.LookupMixIn, name: str, offset: int = 0) tuple[LocalsDictNodeNG, list[nodes.NodeNG]] #
Lookup where the given variable is assigned.
node – The node to look for assignments up to. Any assignments after the given node are ignored.
name – The name of the variable to find assignments for.
offset – The line offset to filter statements up to.
This scope node and the list of assignments associated to the given name according to the scope where it has been found (locals, globals or builtin).
- set_local(name: str, stmt: nodes.NodeNG) None #
Define that the given name is declared in the given statement node.
name – The name that is being defined.
stmt – The statement that defines the given name.