class NodeNG: (source)
Known subclasses: astroid.nodes.Arguments
, astroid.nodes.AssignAttr
, astroid.nodes.AssignName
, astroid.nodes.Attribute
, 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.DelName
, astroid.nodes.Dict
, astroid.nodes.DictUnpack
, astroid.nodes.Ellipsis
, astroid.nodes.EmptyNode
, astroid.nodes.EvaluatedObject
, astroid.nodes.ExtSlice
, astroid.nodes.FormattedValue
, astroid.nodes.IfExp
, astroid.nodes.Index
, astroid.nodes.JoinedStr
, astroid.nodes.Keyword
, astroid.nodes.MatchCase
, astroid.nodes.Name
, astroid.nodes.NamedExpr
, astroid.nodes.node_classes.BaseContainer
, astroid.nodes.node_classes.Pattern
, astroid.nodes.Slice
, astroid.nodes.Starred
, astroid.nodes.Statement
, astroid.nodes.Subscript
, astroid.nodes.UnaryOp
, astroid.nodes.Unknown
, astroid.nodes.Yield
A node of the new Abstract Syntax Tree (AST).
This is the base class for all Astroid node classes.
Method | __init__ |
|
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. These can be Module, FunctionDef, ClassDef, Lambda, or GeneratorExp nodes. |
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. Note: This is after the last symbol. |
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. |
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. |
astroid.nodes.AnnAssign
, astroid.nodes.Arguments
, astroid.nodes.Assert
, astroid.nodes.Assign
, astroid.nodes.AssignAttr
, astroid.nodes.AssignName
, astroid.nodes.Attribute
, 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.DelName
, astroid.nodes.Dict
, astroid.nodes.EvaluatedObject
, astroid.nodes.ExceptHandler
, astroid.nodes.Expr
, astroid.nodes.For
, astroid.nodes.FormattedValue
, astroid.nodes.Global
, astroid.nodes.If
, astroid.nodes.IfExp
, astroid.nodes.Import
, astroid.nodes.ImportFrom
, astroid.nodes.JoinedStr
, astroid.nodes.Keyword
, astroid.nodes.Match
, astroid.nodes.MatchAs
, astroid.nodes.MatchCase
, astroid.nodes.MatchClass
, astroid.nodes.MatchMapping
, astroid.nodes.MatchOr
, astroid.nodes.MatchSequence
, astroid.nodes.MatchSingleton
, astroid.nodes.MatchStar
, astroid.nodes.MatchValue
, astroid.nodes.Name
, astroid.nodes.NamedExpr
, astroid.nodes.node_classes.BaseContainer
, astroid.nodes.Nonlocal
, astroid.nodes.Raise
, astroid.nodes.Return
, astroid.nodes.scoped_nodes.ClassDef
, astroid.nodes.scoped_nodes.FunctionDef
, astroid.nodes.Slice
, astroid.nodes.Starred
, astroid.nodes.Subscript
, astroid.nodes.TryExcept
, astroid.nodes.TryFinally
, astroid.nodes.UnaryOp
, astroid.nodes.While
, astroid.nodes.With
, astroid.nodes.Yield
Parameters | |
lineno:Optional[ | The line that this node appears on in the source code. |
col_offset:Optional[ | The column that this node appears on in the source code. |
parent:Optional[ | The parent node in the syntax tree. |
end_lineno:Optional[ | The last line this node appears on in the source code. |
end_col_offset:Optional[ | The end column this node appears on in the source code. Note: This is after the last symbol. |
astroid.nodes.If
, astroid.nodes.scoped_nodes.ClassDef
, astroid.nodes.scoped_nodes.FunctionDef
, astroid.nodes.TryExcept
, astroid.nodes.TryFinally
, astroid.nodes.While
Parameters | |
lineno:int | The line number to start the range at. |
Returns | |
tuple(int, int or None) | The range of line numbers that this node belongs to, starting at the given line number. |
astroid.nodes.Const
, astroid.nodes.Dict
, astroid.nodes.node_classes.BaseContainer
, astroid.nodes.scoped_nodes.ClassDef
, astroid.nodes.scoped_nodes.FunctionDef
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 | |
bool or Uninferable | The boolean value of this node. |
astroid.nodes.scoped_nodes.ClassDef
Returns | |
bool | True if this defines something that is callable, False otherwise. |
Parameters | |
child:NodeNG | The child node to search sequences for. |
Returns | |
iterable(NodeNG) | The sequence containing the given child node. |
Raises | |
AstroidError | If no sequence could be found that contains the given child. |
astroid.nodes.NamedExpr
, astroid.nodes.scoped_nodes.ClassDef
, astroid.nodes.scoped_nodes.FunctionDef
The first parent frame node.
A frame node is a Module
, FunctionDef
,
ClassDef
or Lambda
.
Parameters | |
future:Literal[ | Undocumented |
Returns | |
Union[ | The first parent frame node. |
astroid.nodes.AnnAssign
, astroid.nodes.Arguments
, astroid.nodes.Assert
, astroid.nodes.Assign
, astroid.nodes.AssignAttr
, astroid.nodes.Attribute
, 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.Dict
, astroid.nodes.ExceptHandler
, astroid.nodes.Expr
, astroid.nodes.For
, astroid.nodes.FormattedValue
, astroid.nodes.If
, astroid.nodes.IfExp
, astroid.nodes.JoinedStr
, astroid.nodes.Keyword
, astroid.nodes.node_classes.BaseContainer
, astroid.nodes.Raise
, astroid.nodes.Return
, astroid.nodes.scoped_nodes.ClassDef
, astroid.nodes.scoped_nodes.FunctionDef
, astroid.nodes.Slice
, astroid.nodes.Starred
, astroid.nodes.Subscript
, astroid.nodes.TryExcept
, astroid.nodes.TryFinally
, astroid.nodes.UnaryOp
, astroid.nodes.While
, astroid.nodes.With
, astroid.nodes.Yield
Returns | |
Iterator[ | Undocumented |
astroid.nodes.scoped_nodes.ClassDef
Parameters | |
node:NodeNG | The node defining the base to look for.
Usually this is a Name node. |
astroid.nodes.EvaluatedObject
Get a generator of the inferred values.
This is the main entry point to the inference system.
See Also
If the instance has some explicit inference function set, it will be called instead of the default interface.
Returns | |
iterable | The inferred values. |
astroid.nodes.scoped_nodes.ClassDef
Instantiate an instance of the defined class.
Note
On anything other than a ClassDef
this will return self.
Returns | |
object | An instance of the defined class. |
astroid.nodes.Compare
, astroid.nodes.Dict
Returns | |
Optional[ | Undocumented |
Parameters | |
child:NodeNG | The child node to search fields for. |
Returns | |
tuple(str, iterable(NodeNG) or NodeNG) | A tuple of the name of the field that contains the child, and the sequence or node that contains the child node. |
Raises | |
AstroidError | If no field could be found that contains the given child. |
astroid.nodes.Statement
Returns | |
NodeNG or None | The next sibling statement node. |
Parameters | |
klass:Union[ | The types of node to search for. |
skip_klass:SkipKlassT | The types of node to ignore. This is useful to ignore
subclasses of klass . |
Returns | |
Union[ | The node of the given types. |
Parameters | |
node:NodeNG | The node to check if it is the child. |
Returns | |
bool | True if this node is the parent of the given node, False otherwise. |
astroid.nodes.Statement
Returns | |
NodeNG or None | The previous sibling statement node. |
Parameters | |
ids:bool | If true, includes the ids with the node type names. |
include_linenos:bool | If true, includes the line numbers and column offsets. |
ast_state:bool | If true, includes information derived from the whole AST like local and global variables. |
indent:str | A string to use to indent the output string. |
max_depth:int | If set to a positive integer, won't return nodes deeper than max_depth in the string. |
max_width:int | 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. |
Returns | |
str | The string representation of the AST. |
astroid.nodes.Decorators
, astroid.nodes.NamedExpr
Returns | |
nodes.LocalsDictNodeNG | The first parent scope node. |
astroid.nodes.NamedExpr
Define that the given name is declared in the given statement node.
This definition is stored on the parent scope node.
See Also
Parameters | |
name:str | The name that is being defined. |
stmt:NodeNG | The statement that defines the given name. |
The first parent node, including self, marked as statement node.
TODO: Deprecate the future parameter and only raise StatementMissing and return nodes.Statement
Parameters | |
future:Literal[ | Undocumented |
Returns | |
Union[ | Undocumented |
Raises | |
AttributeError | If self has no parent attribute |
StatementMissing | If self has no parent attribute and future is True |
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.scoped_nodes.FunctionDef
Attempt to find the line that this node appears on.
We need this method since not all nodes have lineno
set.
Returns | |
Optional[ | Undocumented |
astroid.nodes.Assign
, astroid.nodes.AugAssign
, astroid.nodes.Expr
, astroid.nodes.If
, astroid.nodes.While
, astroid.nodes.Yield
Undocumented
astroid.nodes.Unknown
, astroid.objects.FrozenSet
astroid.nodes.Arguments
, astroid.nodes.Global
, astroid.nodes.Nonlocal
, astroid.nodes.TryExcept
Undocumented
Get a name for nice representation.
This is either name
, attrname
, or the empty string.
Returns | |
str | The nice name. |
astroid.nodes.AnnAssign
, astroid.nodes.Arguments
, astroid.nodes.Assert
, astroid.nodes.Assign
, astroid.nodes.AssignAttr
, astroid.nodes.Attribute
, 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.Dict
, astroid.nodes.EvaluatedObject
, astroid.nodes.ExceptHandler
, astroid.nodes.Expr
, astroid.nodes.For
, astroid.nodes.FormattedValue
, astroid.nodes.If
, astroid.nodes.IfExp
, astroid.nodes.JoinedStr
, astroid.nodes.Keyword
, astroid.nodes.Match
, astroid.nodes.MatchAs
, astroid.nodes.MatchCase
, astroid.nodes.MatchClass
, astroid.nodes.MatchMapping
, astroid.nodes.MatchOr
, astroid.nodes.MatchSequence
, astroid.nodes.MatchStar
, astroid.nodes.MatchValue
, astroid.nodes.NamedExpr
, astroid.nodes.node_classes.BaseContainer
, astroid.nodes.Raise
, astroid.nodes.Return
, astroid.nodes.scoped_nodes.ClassDef
, astroid.nodes.scoped_nodes.FunctionDef
, astroid.nodes.Slice
, astroid.nodes.Starred
, astroid.nodes.Subscript
, astroid.nodes.TryExcept
, astroid.nodes.TryFinally
, astroid.nodes.UnaryOp
, astroid.nodes.While
, astroid.nodes.With
, astroid.nodes.Yield
Node attributes that contain child nodes.
This is redefined in most concrete classes.
astroid.nodes.AnnAssign
, astroid.nodes.Arguments
, astroid.nodes.AssignAttr
, astroid.nodes.AssignName
, astroid.nodes.Attribute
, astroid.nodes.AugAssign
, astroid.nodes.BinOp
, astroid.nodes.BoolOp
, astroid.nodes.Comprehension
, astroid.nodes.Const
, astroid.nodes.DelAttr
, astroid.nodes.DelName
, astroid.nodes.EvaluatedObject
, astroid.nodes.FormattedValue
, astroid.nodes.Global
, astroid.nodes.Import
, astroid.nodes.ImportFrom
, astroid.nodes.Keyword
, astroid.nodes.List
, astroid.nodes.MatchClass
, astroid.nodes.MatchSingleton
, astroid.nodes.Name
, astroid.nodes.Nonlocal
, astroid.nodes.scoped_nodes.ClassDef
, astroid.nodes.scoped_nodes.FunctionDef
, astroid.nodes.Starred
, astroid.nodes.Subscript
, astroid.nodes.Tuple
, astroid.nodes.UnaryOp
astroid.nodes.Assign
, astroid.nodes.For
, astroid.nodes.scoped_nodes.ClassDef
, astroid.nodes.scoped_nodes.FunctionDef
, astroid.nodes.With