module documentation

Undocumented

Class ASTNode This class is dynamically added to the bases of each AST node class.
Class Context Undocumented
Class Instance This class is selectively added to the bases of the following ast nodes: Constant, List, Tuple, Dict, Set.
Class TypeInfo Optionnaly holds type information.
Class Uninferable Special object which is returned when inference fails.
Function are_exclusive return true if the two given statements are mutually exclusive
Function fix_ast Fix a newly created AST tree to be compatible with astuce.
Function get_context Wraps the context ast context classes into a more friendly enumeration.
Function get_full_import_name Get the full path of a name from a from .x import y or import y alias.
Function get_if_statement_ancestor Return the first parent node that is an If node (or None)
Function get_module_parent Returns the parent package of this module or None if not found.
Function get_origin_module Get the origin module fullname from an ast.alias. This string can be used to retreive the ast.Module instance from the Parser.modules dict.
Function is_assign_name Whether this node is the target of an assigment.
Function is_del_name Whether this node is the target of a del statment.
Function is_frame_node Whether this node is a frame.
Function is_orelse Is this If node is part of the the C{else} branch of a parent If node.
Function is_scoped_node Whether this node is a scope.
Function literal_to_ast Transform a literal object into it's AST counterpart.
Function nodes_of_class Get the nodes (including this one or below) of the given types.
Function qname_to_ast Transform a dotted name (i.e twisted.internet.reactor) into it's AST couterparts.
Function relative_to_absolute Convert a relative import path to an absolute one.
Function _get_full_origin_name Get the full path of a name from a from .x import y alias.
Constant _CONTEXT_MAP Undocumented
Constant _END_OF_FRAME_SENTINEL_CONSTANT Undocumented
def are_exclusive(stmt1, stmt2): (source)

return true if the two given statements are mutually exclusive

algorithm : 1) index stmt1's parents 2) climb among stmt2's parents until we find a common parent 3) if the common parent is a If or Try statement, look if nodes are

in exclusive branches
Parameters
stmt1:ASTNodeUndocumented
stmt2:ASTNodeUndocumented
Returns
boolUndocumented
def fix_ast(node, parent): (source)

Fix a newly created AST tree to be compatible with astuce.

Parameters
node:_typing.ASTNodeUndocumented
parent:Optional[_typing.ASTNode]Undocumented
Returns
_typing.ASTNodeUndocumented
@functools.lru_cache(maxsize=None)
def get_context(node): (source)

Wraps the context ast context classes into a more friendly enumeration.

Dynamically created nodes do not have the ctx field, in this case fall back to Load context.

Parameters
node:Union[ast.Attribute, ast.List, ast.Name, ast.Subscript, ast.Starred, ast.Tuple]Undocumented
Returns
ContextUndocumented
def get_full_import_name(alias): (source)

Get the full path of a name from a from .x import y or import y alias.

Note that for static analysis, we don't currently need the submodule information. So imports like:

import c.abc

Will result in 'c' beeing returned.

Parameters
alias:ast.aliasUndocumented
Returns
strUndocumented
def get_if_statement_ancestor(node): (source)

Return the first parent node that is an If node (or None)

Parameters
node:ASTNodeUndocumented
Returns
Optional[ASTNode]Undocumented
def get_module_parent(node): (source)

Returns the parent package of this module or None if not found.

Some code rely on the fact that Module.parent property is always None. So we should not overide this behaviour.

Parameters
node:_typing.ModuleUndocumented
Returns
Optional[_typing.Module]Undocumented
def get_origin_module(alias): (source)

Get the origin module fullname from an ast.alias. This string can be used to retreive the ast.Module instance from the Parser.modules dict.

Note that for static analysis, we don't currently need the submodule information. So imports like:

import c.abc

Will result in 'c' beeing returned.

But:

import c.abc as cabc

Will result in 'c.abc' beeing returned.

Import from like:

# in pack/__init__.py
from .x import y
# in pack/x.py
pass
# if the file is not in the system, it will fail to resolve.

Will result in 'pack.x' beeing returned.

Parameters
alias:ast.aliasUndocumented
Returns
strUndocumented
def is_assign_name(node): (source)

Whether this node is the target of an assigment.

Parameters
node:Union[ast.Name, ast.Attribute]Undocumented
Returns
boolUndocumented
def is_del_name(node): (source)

Whether this node is the target of a del statment.

Parameters
node:Union[ast.Name, ast.Attribute]Undocumented
Returns
boolUndocumented
def is_frame_node(node): (source)

Whether this node is a frame.

Parameters
node:ASTNodeUndocumented
Returns
boolUndocumented
def is_orelse(node): (source)

Is this If node is part of the the C{else} branch of a parent If node.

Parameters
node:ASTNodeUndocumented
Returns
boolUndocumented
Note
Always returns False if C{node} is not an L{ast.If}.
def is_scoped_node(node): (source)

Whether this node is a scope.

Parameters
node:ASTNodeUndocumented
Returns
boolUndocumented
def literal_to_ast(ob): (source)

Transform a literal object into it's AST counterpart.

The object provided may only consist of the following Python builtin types: strings, bytes, numbers, tuples, lists, dicts, sets, booleans, and None.

Normally, AST and literal_to_ast(ast.literal_eval(AST)) are equivalent.

Parameters
ob:AnyUndocumented
Returns
ast.exprUndocumented
def nodes_of_class(self, klass, predicate=None): (source)

Get the nodes (including this one or below) of the given types.

Parameters
klass:Union[Type[ast.AST], Tuple[Type[ast.AST], ...]]The types of node to search for.
predicate:Optional[Callable[[_typing.ASTNode], bool]]Callable that returns False value to ignore more objects.
Returns
Iterator[_typing.ASTNode]The node of the given types.
def qname_to_ast(name): (source)

Transform a dotted name (i.e twisted.internet.reactor) into it's AST couterparts.

Parameters
name:strUndocumented
Returns
Union[ast.Name, ast.Attribute]Undocumented
def relative_to_absolute(node): (source)

Convert a relative import path to an absolute one.

Parameters
node:ast.ImportFromThe "from ... import ..." AST node.
nameThe imported name.
Returns
strThe absolute import path of the module this nodes imports from.
Raises
InferenceErrorif the import is relative and the module could not be found in the system.
def _get_full_origin_name(import_from): (source)

Get the full path of a name from a from .x import y alias.

Parameters
import_from:ast.ImportFromThe node to resolve the name of.
aliasThe alias node
Returns
strThe full import path of the name.
_CONTEXT_MAP = (source)
_END_OF_FRAME_SENTINEL_CONSTANT: int = (source)

Undocumented

Value
430335967