module documentation
(source)

The AstroidBuilder makes astroid from living object and / or from _ast

The builder is not thread safe and can't be used to parse different sources at the same time.

Class ​Astroid​Builder Class for building an astroid tree from source code or from a live module.
Function build​_namespace​_package​_module Undocumented
Function extract​_node Parses some Python code as a module and extracts a designated AST node.
Function open​_source​_file Undocumented
Function parse Parses a source string in order to obtain an astroid AST from it
Constant MISPLACED​_TYPE​_ANNOTATION​_ERROR Undocumented
Variable objects Undocumented
Function _can​_assign​_attr Undocumented
Function _extract​_expressions Find expressions in a call to _TRANSIENT_FUNCTION and extract them.
Function _find​_statement​_by​_line Extracts the statement on a specific line from an AST.
Function _parse​_string Undocumented
Constant _STATEMENT​_SELECTOR Undocumented
Constant _TRANSIENT​_FUNCTION Undocumented
def build_namespace_package_module(name, path): (source)

Undocumented

Parameters
name:strUndocumented
path:List[str]Undocumented
Returns
nodes.ModuleUndocumented
def extract_node(code, module_name=''): (source)

Parses some Python code as a module and extracts a designated AST node.

Statements:

To extract one or more statement nodes, append #@ to the end of the line

Examples:
>>> def x():
>>>   def y():
>>>     return 1 #@

The return statement will be extracted.

>>> class X(object):
>>>   def meth(self): #@
>>>     pass

The function object 'meth' will be extracted.

Expressions:

To extract arbitrary expressions, surround them with the fake function call __(...). After parsing, the surrounded expression will be returned and the whole AST (accessible via the returned node's parent attribute) will look like the function call was never there in the first place.

Examples:
>>> a = __(1)

The const node will be extracted.

>>> def x(d=__(foo.bar)): pass

The node containing the default argument will be extracted.

>>> def foo(a, b):
>>>   return 0 < __(len(a)) < b

The node containing the function call 'len' will be extracted.

If no statements or expressions are selected, the last toplevel statement will be returned.

If the selected statement is a discard statement, (i.e. an expression turned into a statement), the wrapped expression is returned instead.

For convenience, singleton lists are unpacked.

a module. Will be passed through textwrap.dedent first. :param str module_name: The name of the module. :returns: The designated node from the parse tree, or a list of nodes.

Parameters
code:strUndocumented
module​_name:strUndocumented
str codeA piece of Python code that is parsed as
Returns
Union[NodeNG, List[NodeNG]]Undocumented
def open_source_file(filename): (source)

Undocumented

def parse(code, module_name='', path=None, apply_transforms=True): (source)
Parses a source string in order to obtain an astroid AST from it
Parameters
codeUndocumented
module​_nameUndocumented
pathUndocumented
apply​_transformsUndocumented
str codeThe code for the module.
str module​_nameThe name for the module, if any
str pathThe path for the module
bool apply​_transformsApply the transforms for the give code. Use it if you don't want the default transforms to be applied.
MISPLACED_TYPE_ANNOTATION_ERROR: str = (source)

Undocumented

Value
'misplaced type annotation'
objects = (source)

Undocumented

def _can_assign_attr(node, attrname): (source)

Undocumented

def _extract_expressions(node): (source)

Find expressions in a call to _TRANSIENT_FUNCTION and extract them.

The function walks the AST recursively to search for expressions that are wrapped into a call to _TRANSIENT_FUNCTION. If it finds such an expression, it completely removes the function call node from the tree, replacing it by the wrapped expression inside the parent.

expression can be found.

Parameters
node:astroid.bases.NodeNGAn astroid node.
Yields
The sequence of wrapped expressions on the modified tree
def _find_statement_by_line(node, line): (source)

Extracts the statement on a specific line from an AST.

If the line number of node matches line, it will be returned; otherwise its children are iterated and the function is called recursively.

Parameters
node:astroid.bases.NodeNGAn astroid node.
line:intThe line number of the statement to extract.
Returns
astroid.bases.NodeNG or NoneThe statement on the line, or None if no statement for the line can be found.
def _parse_string(data, type_comments=True): (source)

Undocumented

_STATEMENT_SELECTOR: str = (source)

Undocumented

Value
'#@'
_TRANSIENT_FUNCTION: str = (source)

Undocumented

Value
'__'