LocalsDictNodeNG#

class astroid.nodes.LocalsDictNodeNG(lineno: int | None, col_offset: int | None, parent: NodeNG | None, *, end_lineno: int | None, end_col_offset: int | None)[source]#

Bases: LookupMixIn

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[source]#
add_local_node(child_node: nodes.NodeNG, name: str) None

Append a child that should alter the locals of this scope node.

Parameters:
  • child_node – The child node that will alter locals.

  • name – The name of the local that will be altered by the given child node.

items()[source]#

Get the names of the locals and the node that defines the local.

Returns:

The names of locals and their associated node.

Return type:

list(tuple(str, NodeNG))

keys()[source]#

The names of locals defined in this scoped node.

Returns:

The names of the defined locals.

Return type:

list(str)

locals: dict[str, list[InferenceResult]]#

A map of the name of a local variable to the node defining the local.

qname() str[source]#

Get the ‘qualified’ name of the node.

For example: module.name, module.class.name …

Returns:

The qualified name.

Return type:

str

scope() _T[source]#

The first parent node defining a new scope.

Returns:

The first parent scope node.

Return type:

Module or FunctionDef or ClassDef or Lambda or GenExpr

scope_lookup(node: _base_nodes.LookupMixIn, name: str, offset: int = 0) tuple[LocalsDictNodeNG, list[nodes.NodeNG]][source]#

Lookup where the given variable is assigned.

Parameters:
  • 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.

Returns:

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[source]#

Define that the given name is declared in the given statement node.

See also

scope()

Parameters:
  • name – The name that is being defined.

  • stmt – The statement that defines the given name.

values()[source]#

The nodes that define the locals in this scoped node.

Returns:

The nodes that define locals.

Return type:

list(NodeNG)