class NodeNG: (source)
Known subclasses: astroid.mixins.AssignTypeMixin
, astroid.mixins.FilterStmtsMixin
, astroid.mixins.MultiLineBlockMixin
, astroid.mixins.NoChildrenMixin
, astroid.nodes.Attribute
, astroid.nodes.Await
, astroid.nodes.BinOp
, astroid.nodes.BoolOp
, astroid.nodes.Call
, astroid.nodes.Compare
, astroid.nodes.Comprehension
, astroid.nodes.Decorators
, astroid.nodes.Dict
, astroid.nodes.EvaluatedObject
, astroid.nodes.ExtSlice
, astroid.nodes.FormattedValue
, astroid.nodes.IfExp
, astroid.nodes.Index
, astroid.nodes.JoinedStr
, astroid.nodes.Keyword
, astroid.nodes.node_classes.LookupMixIn
, astroid.nodes.node_classes.Pattern
, astroid.nodes.Slice
, astroid.nodes.Statement
, astroid.nodes.Subscript
, astroid.nodes.UnaryOp
, astroid.nodes.Yield
, astroid.objects.Super
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 |
Get the source code that this node represents. |
Method | block |
Get a range from the given line number to where this node ends. |
Method | bool |
Determine the boolean value of this node. |
Method | callable |
Whether this node defines something that is callable. |
Method | child |
Search for the sequence that contains this child. |
Method | eq |
Undocumented |
Method | frame |
The first parent frame node. |
Method | get |
Get the child nodes below this node. |
Method | has |
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 |
Instantiate an instance of the defined class. |
Method | last |
An optimized version of list(get_children())[-1]. |
Method | locate |
Find the field of this node that contains the given child. |
Method | next |
The next sibling statement node. |
Method | node |
Yield parent, grandparent, etc until there are no more. |
Method | nodes |
Get the nodes (including this one or below) of the given types. |
Method | op |
Undocumented |
Method | op |
Undocumented |
Method | parent |
Check if this node is the parent of the given node. |
Method | previous |
The previous sibling statement. |
Method | repr |
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 |
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 |
Whether this node indicates a function. |
Class Variable | is |
Undocumented |
Class Variable | is |
Whether this node indicates a statement. |
Class Variable | optional |
Whether this node optionally assigns a variable. |
Instance Variable | col |
The column that this node appears on in the source code. |
Instance Variable | end |
The end column this node appears on in the source code. |
Instance Variable | end |
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 |
Attempt to find the line that this node appears on. |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Method | _infer |
We don't know how to resolve a statement by default. |
Method | _infer |
Undocumented |
Method | _repr |
Get a name for nice representation. |
Class Variable | _astroid |
Node attributes that contain child nodes. |
Class Variable | _explicit |
Undocumented |
Class Variable | _other |
Node attributes that do not contain child nodes. |
Class Variable | _other |
Attributes that contain AST-dependent fields. |
int|None
= None, col_offset: int|None
= None, parent: NodeNG|None
= None, *, end_lineno: int|None
= None, end_col_offset: int|None
= None):
(source)
¶
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.
astroid.nodes.If
, astroid.nodes.If
, astroid.nodes.node_classes.TryStar
, astroid.nodes.node_classes.TryStar
, astroid.nodes.scoped_nodes.ClassDef
, astroid.nodes.scoped_nodes.FunctionDef
, astroid.nodes.scoped_nodes.Module
, astroid.nodes.TryExcept
, astroid.nodes.TryExcept
, astroid.nodes.TryFinally
, astroid.nodes.TryFinally
, astroid.nodes.While
, astroid.nodes.While
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)
astroid.nodes.Const
, astroid.nodes.Dict
, astroid.nodes.node_classes.BaseContainer
, 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
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
Whether this node defines something that is callable. :returns: Whether this defines something that is callable.
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.
Literal[ None, True]
= None) -> ((nodes.FunctionDef|nodes.Module)|nodes.ClassDef)|nodes.Lambda
:
(source)
¶
astroid.nodes.NamedExpr
, astroid.nodes.scoped_nodes.ClassDef
, astroid.nodes.scoped_nodes.Lambda
, astroid.nodes.scoped_nodes.Module
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.
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.
astroid.nodes.scoped_nodes.ClassDef
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
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
Get a list of the inferred values. .. seealso:: :ref:`inference` :returns: The inferred values. :rtype: list
astroid.nodes.scoped_nodes.ClassDef
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
astroid.nodes.Compare
, astroid.nodes.Dict
An optimized version of list(get_children())[-1].
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.
astroid.nodes.scoped_nodes.Module
, astroid.nodes.Statement
The next sibling statement node. :returns: The next sibling statement node. :rtype: NodeNG or None
@overload
tuple[ type[ _NodesT], type[ _NodesT2]]
, skip_klass: SkipKlassT
= ...) -> Iterator[ _NodesT]|Iterator[ _NodesT2]
:tuple[ type[ _NodesT], type[ _NodesT2], type[ _NodesT3]]
, skip_klass: SkipKlassT
= ...) -> (Iterator[ _NodesT]|Iterator[ _NodesT2])|Iterator[ _NodesT3]
:tuple[ type[ _NodesT], ...]
, skip_klass: SkipKlassT
= ...) -> Iterator[ _NodesT]
: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.
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.
astroid.nodes.scoped_nodes.Module
, astroid.nodes.Statement
The previous sibling statement. :returns: The previous sibling statement node. :rtype: NodeNG or None
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
astroid.nodes.Decorators
, astroid.nodes.NamedExpr
, astroid.nodes.scoped_nodes.LocalsDictNodeNG
The first parent node defining a new scope. These can be Module, FunctionDef, ClassDef, Lambda, or GeneratorExp nodes. :returns: The first parent scope node.
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.
astroid.nodes.scoped_nodes.Module
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
astroid.nodes.Comprehension
, astroid.nodes.For
, astroid.nodes.For
, astroid.nodes.For
, astroid.nodes.NamedExpr
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.
astroid.nodes.Arguments
, astroid.nodes.Comprehension
, astroid.nodes.MatchCase
, astroid.nodes.scoped_nodes.Module
The column that this node appears on in the source code.
astroid.nodes.Arguments
, astroid.nodes.Comprehension
, astroid.nodes.MatchCase
, astroid.nodes.scoped_nodes.Module
The end column this node appears on in the source code. Note: This is after the last symbol.
astroid.nodes.Arguments
, astroid.nodes.Comprehension
, astroid.nodes.MatchCase
, astroid.nodes.scoped_nodes.Module
The last line this node appears on in the source code.
astroid.nodes.Arguments
, astroid.nodes.Comprehension
, astroid.nodes.MatchCase
, astroid.nodes.scoped_nodes.Module
The line that this node appears on in the source code.
astroid.nodes.scoped_nodes.Module
, astroid.objects.PartialFunction
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.
astroid.nodes.Arguments
, astroid.nodes.scoped_nodes.ClassDef
, astroid.nodes.scoped_nodes.FunctionDef
, astroid.nodes.scoped_nodes.Module
The first line that this node appears on in the source code.
Attempt to find the line that this node appears on. We need this method since not all nodes have :attr:`lineno` set.
astroid.mixins.MultiLineBlockMixin
, astroid.nodes.Assign
, astroid.nodes.Assign
, astroid.nodes.scoped_nodes.ClassDef
Undocumented
InferenceContext|None
= None, **kwargs: Any
) -> Generator[ InferenceResult, None, InferenceErrorInfo|None]
:
(source)
¶
astroid.nodes.EvaluatedObject
, astroid.nodes.Unknown
, astroid.objects.FrozenSet
, astroid.objects.Property
, astroid.objects.Super
We don't know how to resolve a statement by default.
astroid.mixins.ImportFromMixin
, astroid.mixins.ImportFromMixin
, astroid.mixins.ImportFromMixin
, astroid.nodes.Arguments
, astroid.nodes.Global
, astroid.nodes.Global
, astroid.nodes.node_classes.TryStar
, astroid.nodes.node_classes.TryStar
, astroid.nodes.Nonlocal
, astroid.nodes.Nonlocal
, astroid.nodes.TryExcept
, astroid.nodes.TryExcept
Undocumented
Get a name for nice representation. This is either :attr:`name`, :attr:`attrname`, or the empty string. :returns: The nice name. :rtype: str
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.
astroid.nodes.AnnAssign
, astroid.nodes.AnnAssign
, astroid.nodes.Arguments
, astroid.nodes.AssignAttr
, astroid.nodes.AssignName
, astroid.nodes.AssignName
, astroid.nodes.AssignName
, astroid.nodes.Attribute
, astroid.nodes.AugAssign
, astroid.nodes.AugAssign
, astroid.nodes.BinOp
, astroid.nodes.BoolOp
, astroid.nodes.Comprehension
, astroid.nodes.Const
, astroid.nodes.DelAttr
, astroid.nodes.DelName
, astroid.nodes.DelName
, astroid.nodes.DelName
, astroid.nodes.EvaluatedObject
, astroid.nodes.FormattedValue
, astroid.nodes.Global
, astroid.nodes.Global
, astroid.nodes.Import
, astroid.nodes.Import
, astroid.nodes.Import
, astroid.nodes.ImportFrom
, astroid.nodes.ImportFrom
, astroid.nodes.ImportFrom
, astroid.nodes.Keyword
, astroid.nodes.List
, astroid.nodes.MatchClass
, astroid.nodes.MatchSingleton
, astroid.nodes.Name
, astroid.nodes.Name
, astroid.nodes.Nonlocal
, astroid.nodes.Nonlocal
, astroid.nodes.scoped_nodes.ClassDef
, astroid.nodes.scoped_nodes.FunctionDef
, astroid.nodes.scoped_nodes.Module
, astroid.nodes.Starred
, astroid.nodes.Subscript
, astroid.nodes.Tuple
, astroid.nodes.UnaryOp
Node attributes that do not contain child nodes.
astroid.nodes.Assign
, astroid.nodes.Assign
, astroid.nodes.For
, astroid.nodes.For
, astroid.nodes.For
, 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.With
, astroid.nodes.With
, astroid.nodes.With
Attributes that contain AST-dependent fields.