class documentation

A node of the new Abstract Syntax Tree (AST). This is the base class for all Astroid node classes.

Method __init__ :param lineno: The line that this node appears on in the source code.
Method __repr__ Undocumented
Method __str__ Undocumented
Method accept Visit this node using the given visitor.
Method as_string Get the source code that this node represents.
Method block_range Get a range from the given line number to where this node ends.
Method bool_value Determine the boolean value of this node.
Method callable Whether this node defines something that is callable.
Method child_sequence Search for the sequence that contains this child.
Method eq Undocumented
Method frame The first parent frame node.
Method get_children Get the child nodes below this node.
Method has_base Check if this node inherits from the given type.
Method infer Get a generator of the inferred values.
Method inferred Get a list of the inferred values.
Method instantiate_class Instantiate an instance of the defined class.
Method last_child An optimized version of list(get_children())[-1].
Method locate_child Find the field of this node that contains the given child.
Method next_sibling The next sibling statement node.
Method node_ancestors Yield parent, grandparent, etc until there are no more.
Method nodes_of_class Get the nodes (including this one or below) of the given types.
Method op_left_associative Undocumented
Method op_precedence Undocumented
Method parent_of Check if this node is the parent of the given node.
Method previous_sibling The previous sibling statement.
Method repr_tree Get a string representation of the AST from this node.
Method root Return the root node of the syntax tree.
Method scope The first parent node defining a new scope.
Method set_local Define that the given name is declared in the given statement node.
Method statement The first parent node, including self, marked as statement node.
Class Variable is_function Whether this node indicates a function.
Class Variable is_lambda Undocumented
Class Variable is_statement Whether this node indicates a statement.
Class Variable optional_assign Whether this node optionally assigns a variable.
Instance Variable col_offset The column that this node appears on in the source code.
Instance Variable end_col_offset The end column this node appears on in the source code.
Instance Variable end_lineno The last line this node appears on in the source code.
Instance Variable lineno The line that this node appears on in the source code.
Instance Variable parent The parent node in the syntax tree.
Instance Variable position Position of keyword(s) and name.
Property fromlineno The first line that this node appears on in the source code.
Property tolineno The last line that this node appears on in the source code.
Method _fixed_source_line Attempt to find the line that this node appears on.
Method _get_assign_nodes Undocumented
Method _get_name_nodes Undocumented
Method _get_return_nodes_skip_functions Undocumented
Method _get_yield_nodes_skip_lambdas Undocumented
Method _infer We don't know how to resolve a statement by default.
Method _infer_name Undocumented
Method _repr_name Get a name for nice representation.
Class Variable _astroid_fields Node attributes that contain child nodes.
Class Variable _explicit_inference Undocumented
Class Variable _other_fields Node attributes that do not contain child nodes.
Class Variable _other_other_fields Attributes that contain AST-dependent fields.
def __init__(self, lineno: int|None = None, col_offset: int|None = None, parent: NodeNG|None = None, *, end_lineno: int|None = None, end_col_offset: int|None = None): (source)
overridden in astroid.nodes.AnnAssign, astroid.nodes.AnnAssign, astroid.nodes.Arguments, astroid.nodes.Assert, astroid.nodes.Assign, astroid.nodes.Assign, astroid.nodes.AssignAttr, astroid.nodes.AssignName, astroid.nodes.AssignName, astroid.nodes.AssignName, astroid.nodes.Attribute, astroid.nodes.AugAssign, astroid.nodes.AugAssign, astroid.nodes.Await, astroid.nodes.BinOp, astroid.nodes.BoolOp, astroid.nodes.Call, astroid.nodes.Compare, astroid.nodes.Comprehension, astroid.nodes.Const, astroid.nodes.Decorators, astroid.nodes.DelAttr, astroid.nodes.Delete, astroid.nodes.Delete, astroid.nodes.DelName, astroid.nodes.DelName, astroid.nodes.DelName, astroid.nodes.Dict, astroid.nodes.EvaluatedObject, astroid.nodes.ExceptHandler, astroid.nodes.ExceptHandler, astroid.nodes.ExceptHandler, astroid.nodes.Expr, astroid.nodes.For, astroid.nodes.For, astroid.nodes.For, astroid.nodes.FormattedValue, astroid.nodes.Global, astroid.nodes.Global, astroid.nodes.If, astroid.nodes.If, astroid.nodes.IfExp, astroid.nodes.Import, astroid.nodes.Import, astroid.nodes.Import, astroid.nodes.ImportFrom, astroid.nodes.ImportFrom, astroid.nodes.ImportFrom, astroid.nodes.JoinedStr, astroid.nodes.Keyword, astroid.nodes.Match, astroid.nodes.Match, astroid.nodes.MatchAs, astroid.nodes.MatchAs, astroid.nodes.MatchCase, astroid.nodes.MatchClass, astroid.nodes.MatchMapping, astroid.nodes.MatchMapping, astroid.nodes.MatchOr, astroid.nodes.MatchSequence, astroid.nodes.MatchSingleton, astroid.nodes.MatchStar, astroid.nodes.MatchStar, astroid.nodes.MatchValue, astroid.nodes.Name, astroid.nodes.Name, astroid.nodes.NamedExpr, astroid.nodes.node_classes.BaseContainer, astroid.nodes.node_classes.TryStar, astroid.nodes.node_classes.TryStar, astroid.nodes.Nonlocal, astroid.nodes.Nonlocal, astroid.nodes.Raise, astroid.nodes.Return, astroid.nodes.scoped_nodes.ClassDef, astroid.nodes.scoped_nodes.DictComp, astroid.nodes.scoped_nodes.GeneratorExp, astroid.nodes.scoped_nodes.Lambda, astroid.nodes.scoped_nodes.ListComp, astroid.nodes.scoped_nodes.Module, astroid.nodes.scoped_nodes.SetComp, astroid.nodes.Slice, astroid.nodes.Starred, astroid.nodes.Subscript, astroid.nodes.TryExcept, astroid.nodes.TryExcept, astroid.nodes.TryFinally, astroid.nodes.TryFinally, astroid.nodes.UnaryOp, astroid.nodes.While, astroid.nodes.While, astroid.nodes.With, astroid.nodes.With, astroid.nodes.With, astroid.nodes.Yield, astroid.objects.Super

:param lineno: The line that this node appears on in the source code. :param col_offset: The column that this node appears on in the source code. :param parent: The parent node in the syntax tree. :param end_lineno: The last line this node appears on in the source code. :param end_col_offset: The end column this node appears on in the source code. Note: This is after the last symbol.

def __repr__(self) -> str: (source)

Undocumented

def __str__(self) -> str: (source)

Undocumented

def accept(self, visitor): (source)

Visit this node using the given visitor.

def as_string(self) -> str: (source)

Get the source code that this node represents.

def block_range(self, lineno): (source)

Get a range from the given line number to where this node ends. :param lineno: The line number to start the range at. :type lineno: int :returns: The range of line numbers that this node belongs to, starting at the given line number. :rtype: tuple(int, int or None)

def bool_value(self, context: InferenceContext|None = None): (source)

Determine the boolean value of this node. The boolean value of a node can have three possible values: * False: For instance, empty data structures, False, empty strings, instances which return explicitly False from the __nonzero__ / __bool__ method. * True: Most of constructs are True by default: classes, functions, modules etc * Uninferable: The inference engine is uncertain of the node's value. :returns: The boolean value of this node. :rtype: bool or Uninferable

def callable(self) -> bool: (source)

Whether this node defines something that is callable. :returns: Whether this defines something that is callable.

def child_sequence(self, child): (source)

Search for the sequence that contains this child. :param child: The child node to search sequences for. :type child: NodeNG :returns: The sequence containing the given child node. :rtype: iterable(NodeNG) :raises AstroidError: If no sequence could be found that contains the given child.

def eq(self, value) -> bool: (source)

Undocumented

def frame(self, *, future: Literal[None, True] = None) -> ((nodes.FunctionDef|nodes.Module)|nodes.ClassDef)|nodes.Lambda: (source)

The first parent frame node. A frame node is a :class:`Module`, :class:`FunctionDef`, :class:`ClassDef` or :class:`Lambda`. :returns: The first parent frame node.

def get_children(self) -> Iterator[NodeNG]: (source)
overridden in astroid.mixins.NoChildrenMixin, astroid.nodes.AnnAssign, astroid.nodes.AnnAssign, astroid.nodes.Arguments, astroid.nodes.Assert, astroid.nodes.Assign, astroid.nodes.Assign, astroid.nodes.AssignAttr, astroid.nodes.Attribute, astroid.nodes.AugAssign, astroid.nodes.AugAssign, astroid.nodes.Await, astroid.nodes.BinOp, astroid.nodes.BoolOp, astroid.nodes.Call, astroid.nodes.Compare, astroid.nodes.Comprehension, astroid.nodes.Decorators, astroid.nodes.DelAttr, astroid.nodes.Delete, astroid.nodes.Delete, astroid.nodes.Dict, astroid.nodes.ExceptHandler, astroid.nodes.ExceptHandler, astroid.nodes.ExceptHandler, astroid.nodes.Expr, astroid.nodes.For, astroid.nodes.For, astroid.nodes.For, astroid.nodes.FormattedValue, astroid.nodes.If, astroid.nodes.If, astroid.nodes.IfExp, astroid.nodes.JoinedStr, astroid.nodes.Keyword, astroid.nodes.node_classes.BaseContainer, astroid.nodes.node_classes.TryStar, astroid.nodes.node_classes.TryStar, astroid.nodes.Raise, astroid.nodes.Return, astroid.nodes.scoped_nodes.ClassDef, astroid.nodes.scoped_nodes.DictComp, astroid.nodes.scoped_nodes.GeneratorExp, astroid.nodes.scoped_nodes.Lambda, astroid.nodes.scoped_nodes.ListComp, astroid.nodes.scoped_nodes.Module, astroid.nodes.scoped_nodes.SetComp, astroid.nodes.Slice, astroid.nodes.Starred, astroid.nodes.Subscript, astroid.nodes.TryExcept, astroid.nodes.TryExcept, astroid.nodes.TryFinally, astroid.nodes.TryFinally, astroid.nodes.UnaryOp, astroid.nodes.While, astroid.nodes.While, astroid.nodes.With, astroid.nodes.With, astroid.nodes.With, astroid.nodes.Yield

Get the child nodes below this node.

def has_base(self, node) -> bool: (source)

Check if this node inherits from the given type. :param node: The node defining the base to look for. Usually this is a :class:`Name` node. :type node: NodeNG

def infer(self, context: InferenceContext|None = None, **kwargs: Any) -> Generator[InferenceResult, None, None]: (source)

Get a generator of the inferred values. This is the main entry point to the inference system. .. seealso:: :ref:`inference` If the instance has some explicit inference function set, it will be called instead of the default interface. :returns: The inferred values. :rtype: iterable

def inferred(self): (source)

Get a list of the inferred values. .. seealso:: :ref:`inference` :returns: The inferred values. :rtype: list

def instantiate_class(self): (source)

Instantiate an instance of the defined class. .. note:: On anything other than a :class:`ClassDef` this will return self. :returns: An instance of the defined class. :rtype: object

def last_child(self) -> NodeNG|None: (source)

An optimized version of list(get_children())[-1].

def locate_child(self, child): (source)

Find the field of this node that contains the given child. :param child: The child node to search fields for. :type child: NodeNG :returns: A tuple of the name of the field that contains the child, and the sequence or node that contains the child node. :rtype: tuple(str, iterable(NodeNG) or NodeNG) :raises AstroidError: If no field could be found that contains the given child.

def next_sibling(self): (source)

The next sibling statement node. :returns: The next sibling statement node. :rtype: NodeNG or None

def node_ancestors(self) -> Iterator[NodeNG]: (source)

Yield parent, grandparent, etc until there are no more.

@overload
def nodes_of_class(self, klass: type[_NodesT], skip_klass: SkipKlassT = ...) -> Iterator[_NodesT]:
@overload
def nodes_of_class(self, klass: tuple[type[_NodesT], type[_NodesT2]], skip_klass: SkipKlassT = ...) -> Iterator[_NodesT]|Iterator[_NodesT2]:
@overload
def nodes_of_class(self, klass: tuple[type[_NodesT], type[_NodesT2], type[_NodesT3]], skip_klass: SkipKlassT = ...) -> (Iterator[_NodesT]|Iterator[_NodesT2])|Iterator[_NodesT3]:
@overload
def nodes_of_class(self, klass: tuple[type[_NodesT], ...], skip_klass: SkipKlassT = ...) -> Iterator[_NodesT]:
(source)

Get the nodes (including this one or below) of the given types. :param klass: The types of node to search for. :param skip_klass: The types of node to ignore. This is useful to ignore subclasses of :attr:`klass`. :returns: The node of the given types.

def op_left_associative(self) -> Literal[True]: (source)

Undocumented

def op_precedence(self): (source)
def parent_of(self, node) -> bool: (source)

Check if this node is the parent of the given node. :param node: The node to check if it is the child. :type node: NodeNG :returns: Whether this node is the parent of the given node.

def previous_sibling(self): (source)

The previous sibling statement. :returns: The previous sibling statement node. :rtype: NodeNG or None

def repr_tree(self, ids=False, include_linenos=False, ast_state=False, indent=' ', max_depth=0, max_width=80) -> str: (source)

Get a string representation of the AST from this node. :param ids: If true, includes the ids with the node type names. :type ids: bool :param include_linenos: If true, includes the line numbers and column offsets. :type include_linenos: bool :param ast_state: If true, includes information derived from the whole AST like local and global variables. :type ast_state: bool :param indent: A string to use to indent the output string. :type indent: str :param max_depth: If set to a positive integer, won't return nodes deeper than max_depth in the string. :type max_depth: int :param max_width: Attempt to format the output string to stay within this number of characters, but can exceed it under some circumstances. Only positive integer values are valid, the default is 80. :type max_width: int :returns: The string representation of the AST. :rtype: str

def root(self) -> nodes.Module: (source)

Return the root node of the syntax tree. :returns: The root node.

def scope(self) -> nodes.LocalsDictNodeNG: (source)

The first parent node defining a new scope. These can be Module, FunctionDef, ClassDef, Lambda, or GeneratorExp nodes. :returns: The first parent scope node.

def set_local(self, name: str, stmt: NodeNG): (source)

Define that the given name is declared in the given statement node. This definition is stored on the parent scope node. .. seealso:: :meth:`scope` :param name: The name that is being defined. :param stmt: The statement that defines the given name.

@overload
def statement(self, *, future: None = ...) -> nodes.Statement|nodes.Module:
@overload
def statement(self, *, future: Literal[True]) -> nodes.Statement:
(source)

The first parent node, including self, marked as statement node. TODO: Deprecate the future parameter and only raise StatementMissing and return nodes.Statement :raises AttributeError: If self has no parent attribute :raises StatementMissing: If self has no parent attribute and future is True

is_function: ClassVar[bool] = (source)

Whether this node indicates a function.

is_lambda: ClassVar[bool] = (source)

Undocumented

is_statement: ClassVar[bool] = (source)

Whether this node indicates a statement.

optional_assign: ClassVar[bool] = (source)

Whether this node optionally assigns a variable. This is for loop assignments because loop won't necessarily perform an assignment if the loop has no iterations. This is also the case from comprehensions in Python 2.

col_offset: int|None = (source)

The column that this node appears on in the source code.

end_col_offset: int|None = (source)

The end column this node appears on in the source code. Note: This is after the last symbol.

end_lineno: int|None = (source)

The last line this node appears on in the source code.

The parent node in the syntax tree.

Position of keyword(s) and name. Used as fallback for block nodes which might not provide good enough positional information. E.g. ClassDef, FunctionDef.

@cached_property
fromlineno: int|None = (source)
@cached_property
tolineno: int|None = (source)

The last line that this node appears on in the source code.

def _fixed_source_line(self) -> int|None: (source)

Attempt to find the line that this node appears on. We need this method since not all nodes have :attr:`lineno` set.

def _get_name_nodes(self): (source)

Undocumented

def _get_return_nodes_skip_functions(self): (source)
def _infer(self, context: InferenceContext|None = None, **kwargs: Any) -> Generator[InferenceResult, None, InferenceErrorInfo|None]: (source)
def _repr_name(self) -> str: (source)

Get a name for nice representation. This is either :attr:`name`, :attr:`attrname`, or the empty string. :returns: The nice name. :rtype: str

_astroid_fields: ClassVar[tuple[str, ...]] = (source)
overridden in astroid.nodes.AnnAssign, astroid.nodes.AnnAssign, astroid.nodes.Arguments, astroid.nodes.Assert, astroid.nodes.Assign, astroid.nodes.Assign, astroid.nodes.AssignAttr, astroid.nodes.Attribute, astroid.nodes.AugAssign, astroid.nodes.AugAssign, astroid.nodes.Await, astroid.nodes.BinOp, astroid.nodes.BoolOp, astroid.nodes.Call, astroid.nodes.Compare, astroid.nodes.Comprehension, astroid.nodes.Decorators, astroid.nodes.DelAttr, astroid.nodes.Delete, astroid.nodes.Delete, astroid.nodes.Dict, astroid.nodes.EvaluatedObject, astroid.nodes.ExceptHandler, astroid.nodes.ExceptHandler, astroid.nodes.ExceptHandler, astroid.nodes.Expr, astroid.nodes.For, astroid.nodes.For, astroid.nodes.For, astroid.nodes.FormattedValue, astroid.nodes.If, astroid.nodes.If, astroid.nodes.IfExp, astroid.nodes.JoinedStr, astroid.nodes.Keyword, astroid.nodes.Match, astroid.nodes.Match, astroid.nodes.MatchAs, astroid.nodes.MatchAs, astroid.nodes.MatchCase, astroid.nodes.MatchClass, astroid.nodes.MatchMapping, astroid.nodes.MatchMapping, astroid.nodes.MatchOr, astroid.nodes.MatchSequence, astroid.nodes.MatchStar, astroid.nodes.MatchStar, astroid.nodes.MatchValue, astroid.nodes.NamedExpr, astroid.nodes.node_classes.BaseContainer, astroid.nodes.node_classes.TryStar, astroid.nodes.node_classes.TryStar, astroid.nodes.Raise, astroid.nodes.Return, astroid.nodes.scoped_nodes.ClassDef, astroid.nodes.scoped_nodes.DictComp, astroid.nodes.scoped_nodes.GeneratorExp, astroid.nodes.scoped_nodes.Lambda, astroid.nodes.scoped_nodes.ListComp, astroid.nodes.scoped_nodes.Module, astroid.nodes.scoped_nodes.SetComp, astroid.nodes.Slice, astroid.nodes.Starred, astroid.nodes.Subscript, astroid.nodes.TryExcept, astroid.nodes.TryExcept, astroid.nodes.TryFinally, astroid.nodes.TryFinally, astroid.nodes.UnaryOp, astroid.nodes.While, astroid.nodes.While, astroid.nodes.With, astroid.nodes.With, astroid.nodes.With, astroid.nodes.Yield

Node attributes that contain child nodes. This is redefined in most concrete classes.

_explicit_inference: InferFn|None = (source)

Undocumented