class documentation

This class is dynamically added to the bases of each AST node class.

Method infer Undocumented
Method locate_child 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_ancestors Yield parent, grandparent, etc until there are no more.
Method parent_of 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_lineno Undocumented
Class Variable parent None for Modules.
Property children Build and return the children of this node.
Property first_child 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_child Return the lasts child of this node.
Property lineno Undocumented
Property locals Undocumented
Property next Return the next sibling of this node.
Property next_siblings 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_siblings 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_package Undocumented
Class Variable _locals Undocumented
Class Variable _modname Undocumented
Class Variable _parser Undocumented
Property _is_from_decorator Return True if the node is the child of a decorator
def infer(self, context=None): (source)

Undocumented

Parameters
context:OptionalInferenceContextUndocumented
Returns
Iterator[_typing.ASTNode]Undocumented
def locate_child(self, child, recurse=False): (source)

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:ASTNodeUndocumented
recurse:boolUndocumented
Returns
tuple(str, iterable(ASTNode) or ASTNode)Undocumented
Raises
ValueErrorIf no field could be found that contains the given child.
@lru_cache()
def lookup(self, name, offset=0): (source)

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:strThe name of the variable to find assignments for.
offset:intThe 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.
def node_ancestors(self): (source)

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

Returns
Iterator[_typing.ASTNode]Undocumented
def parent_of(self, node): (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: ASTNode :returns: True if this node is the parent of the given node,

False otherwise.
Parameters
node:ASTNodeUndocumented
Returns
boolUndocumented
def resolve(self, basename): (source)

Resolve a basename to get its fully qualified name in the context of self.

Parameters
selfThe node representing the context in which to resolve the base name.
basename:strThe partial base name to resolve.
Returns
strThe fully resolved base name.
@lru_cache()
def unparse(self): (source)

Undocumented

Returns
strUndocumented
end_lineno = (source)

Undocumented

None for Modules.

@cached_property
children: Sequence[_typing.ASTNode] = (source)

Build and return the children of this node.

Returns
A list of children.
@cached_property
first_child: _typing.ASTNode = (source)

Return the first child of this node.

Returns
The child.
Raises
LastNodeErrorWhen the node does not have children.
@cached_property
frame: _typing.FrameNodeT = (source)

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.

@cached_property
kind: str = (source)

Return the kind of this node.

Returns
The node kind.
@cached_property
last_child: _typing.ASTNode = (source)

Return the lasts child of this node.

Returns
The child.
Raises
LastNodeErrorWhen the node does not have children.
@cached_property
lineno: int = (source)

Undocumented

@cached_property
locals: Dict[str, List[_typing.LocalsAssignT]] = (source)

Undocumented

@cached_property
next: _typing.ASTNode = (source)

Return the next sibling of this node.

Returns
The sibling.
Raises
LastNodeErrorWhen the node does not have next siblings.
@cached_property
next_siblings: Sequence[_typing.ASTNode] = (source)

Return the next siblings of this node, starting from the closest.

Returns
The next siblings.
@cached_property
position: int = (source)

Tell the position of this node amongst its siblings.

Returns
The node position amongst its siblings.
Raises
RootNodeErrorWhen the node doesn't have a parent.
@cached_property
previous: _typing.ASTNode = (source)

Return the previous sibling of this node.

Returns
The sibling.
Raises
LastNodeErrorWhen the node does not have previous siblings.
@cached_property
previous_siblings: Sequence[_typing.ASTNode] = (source)

Return the previous siblings of this node, starting from the closest.

Returns
The previous siblings.

Get the 'qualified' name of the node.

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

Returns
The qualified name.
@cached_property
root: Module = (source)

Return the root node of the syntax tree.

Returns
The root node.
@cached_property
scope: _typing.ScopedNodeT = (source)

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.

@cached_property
siblings: Sequence[_typing.ASTNode] = (source)

Return the siblings of this node.

Returns
The siblings.
@cached_property
statement: Union[_typing.ASTstmt, _typing.Module] = (source)

The first parent node, including self, marked as statement node. When called on a Module this returns self.

def _report(self, descr, lineno_offset=0): (source)

Log an error or warning about this node object.

Parameters
descr:strUndocumented
lineno_offset:intUndocumented
_filename: Optional[str] = (source)

Undocumented

_is_package: bool = (source)

Undocumented

_modname: Optional[str] = (source)

Undocumented

_parser: Parser = (source)

Undocumented

@cached_property
_is_from_decorator: bool = (source)

Return True if the node is the child of a decorator