class ASTNode: (source)
Known subclasses: astuce._typing.alias
, astuce._typing.AnnAssign
, astuce._typing.arg
, astuce._typing.Assign
, astuce._typing.ASTexpr
, astuce._typing.ASTNode
, astuce._typing.ASTstmt
, astuce._typing.AsyncFor
, astuce._typing.AsyncFunctionDef
, astuce._typing.Attribute
, astuce._typing.AugAssign
, astuce._typing.BinOp
, astuce._typing.ClassDef
, astuce._typing.ConcreteInstance
, astuce._typing.DictComp
, astuce._typing.Expr
, astuce._typing.For
, astuce._typing.FunctionDef
, astuce._typing.GeneratorExp
, astuce._typing.IfExp
, astuce._typing.Import
, astuce._typing.ImportFrom
, astuce._typing.Lambda
, astuce._typing.ListComp
, astuce._typing.Module
, astuce._typing.Name
, astuce._typing.SetComp
, astuce._typing.Subscript
This class is dynamically added to the bases of each AST node class.
Method | infer |
Undocumented |
Method | locate |
Find the field of this node that contains the given child. :param child: The child node to search fields for. :param recurse: Whether to recurse in all nested children to find the node. :type child: ASTNode :returns: A tuple of the name of the field that contains the child,... |
Method | lookup |
Lookup where the given variable is assigned. |
Method | node |
Yield parent, grandparent, etc until there are no more. |
Method | parent |
Check if this node is the parent of the given node. :param node: The node to check if it is the child. :type node: ASTNode :returns: True if this node is the parent of the given node, |
Method | resolve |
Resolve a basename to get its fully qualified name in the context of self. |
Method | unparse |
Undocumented |
Class Variable | end |
Undocumented |
Class Variable | parent |
None for Modules. |
Property | children |
Build and return the children of this node. |
Property | first |
Return the first child of this node. |
Property | frame |
Returns the first parent ast.Lambda , ast.FunctionDef , ast.AsyncFunctionDef ,`ast.ClassDef` or ast.Module . |
Property | kind |
Return the kind of this node. |
Property | last |
Return the lasts child of this node. |
Property | lineno |
Undocumented |
Property | locals |
Undocumented |
Property | next |
Return the next sibling of this node. |
Property | next |
Return the next siblings of this node, starting from the closest. |
Property | position |
Tell the position of this node amongst its siblings. |
Property | previous |
Return the previous sibling of this node. |
Property | previous |
Return the previous siblings of this node, starting from the closest. |
Property | qname |
Get the 'qualified' name of the node. |
Property | root |
Return the root node of the syntax tree. |
Property | scope |
The scope is which this expression can be resolved. This is generally equal to the frame, expect for nodes defined in decorators, in this case the scope is the upper scope. |
Property | siblings |
Return the siblings of this node. |
Property | statement |
The first parent node, including self, marked as statement node. When called on a Module this returns self. |
Method | _report |
Log an error or warning about this node object. |
Class Variable | _filename |
Undocumented |
Class Variable | _is |
Undocumented |
Class Variable | _locals |
Undocumented |
Class Variable | _modname |
Undocumented |
Class Variable | _parser |
Undocumented |
Property | _is |
Return True if the node is the child of a decorator |
Undocumented
Parameters | |
context:OptionalInferenceContext | Undocumented |
Returns | |
Iterator[ | Undocumented |
Find the field of this node that contains the given child. :param child: The child node to search fields for. :param recurse: Whether to recurse in all nested children to find the node. :type child: ASTNode :returns: A tuple of the name of the field that contains the child,
and the sequence or node that contains the child node.
Parameters | |
child:ASTNode | Undocumented |
recurse:bool | Undocumented |
Returns | |
tuple(str , iterable(ASTNode) or ASTNode) | Undocumented |
Raises | |
ValueError | If no field could be found that contains the given child. |
Lookup where the given variable is assigned.
The lookup starts from self's scope. If self is not a frame itself and the name is found in the inner frame locals, statements will be filtered to remove ignorable statements according to self's location.
Parameters | |
name:str | The name of the variable to find assignments for. |
offset:int | The line offset to filter statements up to. |
Returns | |
tuple[ASTNode , List[_typing.LocalsAssignT]] | The scope node and the list of assignments associated to the given name according to the scope node where it has been found. |
Yield parent, grandparent, etc until there are no more.
Returns | |
Iterator[ | Undocumented |
Return the first child of this node.
Returns | |
The child. | |
Raises | |
LastNodeError | When the node does not have children. |
Returns the first parent ast.Lambda
, ast.FunctionDef
, ast.AsyncFunctionDef
,`ast.ClassDef` or ast.Module
.
The parent of a frame is always another frame.
Lambda frame is special because we can't define further locals except the one defined in the arguments.
When called on a Module
this returns self.
Return the lasts child of this node.
Returns | |
The child. | |
Raises | |
LastNodeError | When the node does not have children. |
Return the next sibling of this node.
Returns | |
The sibling. | |
Raises | |
LastNodeError | When the node does not have next siblings. |
Tell the position of this node amongst its siblings.
Returns | |
The node position amongst its siblings. | |
Raises | |
RootNodeError | When the node doesn't have a parent. |
Return the previous sibling of this node.
Returns | |
The sibling. | |
Raises | |
LastNodeError | When the node does not have previous siblings. |
Get the 'qualified' name of the node.
For example: module.name, module.class.name ...
Returns | |
The qualified name. |
The scope is which this expression can be resolved. This is generally equal to the frame, expect for nodes defined in decorators, in this case the scope is the upper scope.
Returns the first parent frame or generator/comprehension.
When called on a Module
this returns self.
The first parent node, including self, marked as statement node.
When called on a Module
this returns self.