Various bits of reusable code related to astroid.nodes.NodeNG
node processing.
Class |
|
A NodeVisitor subclass that walks the abstract syntax tree and allows modification of nodes. The NodeTransformer will walk the AST and use the return value of the visitor methods to replace or remove the old node... |
Class |
|
A node visitor base class that walks the abstract syntax tree and calls a visitor function for every node found. This function may return a value which is forwarded by the visit method. This class is meant to be subclassed, with the subclass adding visitor methods... |
Class |
|
Builds a signature, parameter by parameter, with customizable value formatter and signature classes. |
Class |
|
Formats values stored in AST expressions back to source code. Used for presenting default values of parameters and annotations. |
Function | bind |
Binds the arguments of a function call to that function's signature. :raise TypeError: If the arguments do not match the signature. |
Function | build |
Builds inspect.Signature representing this function's parameters and return value. |
Function | copy |
Copy source location (lineno , col_offset , end_lineno , and end_col_offset attributes) from old_node to new_node if possible, and return new_node. |
Function | extract |
Convert a python expression to ast. |
Function | extract |
Extract the "str" part from annotations like "Final[str]". |
Function | fix |
When you compile a node tree with compile(), the compiler expects lineno and col_offset attributes for every node that supports them. This is rather tedious to fill in for generated nodes, so this helper adds these attributes recursively where not already set, by setting them to the values of the parent node... |
Function | get |
Get the full path of a name from a from x import y statement. |
Function | infer |
Infer an expression's type. :param expr: The expression's AST. :return: A type annotation, or None if the expression has no obvious type. |
Function | is |
A name is an expression composed by astroid.nodes.Attribute and astroid.nodes.Name nodes :returns: True if value is a valid name. |
Function | is |
Return True if the If statement is a typing guard. |
Function | is |
Return True if one of the parent(s) of a node is a typing guard. |
Function | iter |
Given a node, get the fields names and their values. We need the fields names in NodeTransformer. |
Function | iter |
Undocumented |
Function | literal |
Safely evaluate an expression node or a string containing a Python expression. The string or node provided may only consist of the following Python literal structures: strings, bytes, numbers, tuples, lists, dicts, sets, booleans, and None. |
Function | merge |
Undocumented |
Function | node2dottedname |
Resove expression composed by astroid.nodes.Attribute and astroid.nodes.Name nodes to a list of names. |
Function | node2fullname |
Return ctx.expand_name(name) if expr is a valid name, or None. |
Function | resolve |
Resolve a name from an aliased import to its original name. |
Function | resolve |
Resolve a basename to get its fully qualified name. |
Function | to |
This function convert a node tree back into python sourcecode. |
Function | unstring |
Replace all strings in the given expression by parsed versions. :return: The unstringed node. If parsing fails, an error is logged |
Variable | nodefactory |
Acts like every node arguments can be passed to the constructor method. |
Class | _ |
Implementation of unstring_annotation . |
Class | _ |
Undocumented |
Class | _ |
Easy create NodeNG instances. |
Function | _annotation |
Undocumented |
Function | _annotation |
Undocumented |
Function | _is |
Undocumented |
Function | _iter |
Undocumented |
Binds the arguments of a function call to that function's signature. :raise TypeError: If the arguments do not match the signature.
Parameters | |
sig:inspect.Signature | Undocumented |
call:astroid.nodes.Call | Undocumented |
Returns | |
inspect.BoundArguments | Undocumented |
Builds inspect.Signature
representing this function's parameters and return value.
Parameters | |
func:Union[ | Undocumented |
Returns | |
inspect.Signature | Undocumented |
Raises | |
ValueError | If the function has invalid parameters. |
Copy source location (lineno
, col_offset
, end_lineno
, and end_col_offset
attributes) from old_node to new_node if possible, and return new_node.
Parameters | |
newastroid.nodes.NodeNG | Undocumented |
oldastroid.nodes.NodeNG | Undocumented |
Returns | |
astroid.nodes.NodeNG | Undocumented |
Convert a python expression to ast.
Can raise SyntaxError
if invalid python sytax or if got statements instead of expression.
Parameters | |
expr:str | Undocumented |
filename:Optional[ | Undocumented |
allowbool | Undocumented |
Returns | |
astroid.nodes.NodeNG | Undocumented |
Extract the "str" part from annotations like "Final[str]".
@raises ValueError: If the "Final" annotation is not valid.
Parameters | |
annotation:astroid.nodes.Subscript | Undocumented |
Returns | |
astroid.nodes.NodeNG | Undocumented |
When you compile a node tree with compile(), the compiler expects lineno and col_offset attributes for every node that supports them. This is rather tedious to fill in for generated nodes, so this helper adds these attributes recursively where not already set, by setting them to the values of the parent node. It works recursively starting at node.
Parameters | |
node:astroid.nodes.NodeNG | Undocumented |
Returns | |
astroid.nodes.NodeNG | Undocumented |
Return True if the If statement is a typing guard.
Parameters | |
node:astroid.nodes.If | Undocumented |
Returns | |
bool | Undocumented |
Return True if one of the parent(s) of a node is a typing guard.
Parameters | |
node:Optional[ | Undocumented |
ctx:_model.ApiObject | Undocumented |
Returns | |
bool | Undocumented |
Undocumented
Parameters | |
node:astroid.nodes.NodeNG | Undocumented |
Returns | |
Iterator[ | Undocumented |
Safely evaluate an expression node or a string containing a Python expression. The string or node provided may only consist of the following Python literal structures: strings, bytes, numbers, tuples, lists, dicts, sets, booleans, and None.
Parameters | |
nodeUnion[ | Undocumented |
Returns | |
Any | Undocumented |
Resove expression composed by astroid.nodes.Attribute
and astroid.nodes.Name
nodes to a list of names.
Parameters | |
node:Optional[ | Undocumented |
strict:bool | Undocumented |
Returns | |
Optional[ | Undocumented |
Notes | |
Supports variants AssignAttr and AssignName . | |
Strips the subscript slice, i.e. Generic[T] -> Generic , except if scrict=True. |
This function convert a node tree back into python sourcecode.
Parameters | |
expr:astroid.nodes.NodeNG | Undocumented |
Returns | |
str | Undocumented |
Replace all strings in the given expression by parsed versions. :return: The unstringed node. If parsing fails, an error is logged
and the original node is returned.
Parameters | |
node:astroid.nodes.NodeNG | Undocumented |
Returns | |
astroid.nodes.NodeNG | Undocumented |
Raises | |
SyntaxError | if the annotation is invalid. |