class documentation

class Parser: (source)

View In Hierarchy

Object to keep track of parsed modules and inferred nodes.

Method __init__ Undocumented
Method add Add a module to the parser and make compatible with astuce inference system.
Method invalidate_inference_cache Clears the inference cache.
Method parse Parse the python source string into a ast.Module instance, and make compatible with astuce inference system.
Method unparse Unparse an ast.AST object and generate a code string.
Class Variable max_inferable_values Undocumented
Instance Variable modules The parsed modules.
Method _init_new_node A method that must be called for all nodes in the tree as well as inferred (created) nodes.
Method _new_context Create a fresh inference context.
Instance Variable _assignattr A list to store assignments to attributes.
Instance Variable _inference_cache Inferred node contexts to their mapped results.
Instance Variable _wildcard_import Store wildcard ImportFrom to resolve them after building.
def __init__(self): (source)

Undocumented

def add(self, mod, modname, *, is_package=False, **kw): (source)

Add a module to the parser and make compatible with astuce inference system.

This method will apply a set of harmless transformations:

__all__.extend(a) -> __all__ += a
__all__.append(a) -> __all__ += [a]
Parameters
mod:ast.ModuleUndocumented
modname:strUndocumented
is_package:boolUndocumented
**kw:AnyUndocumented
Returns
_typing.ModuleUndocumented
def invalidate_inference_cache(self): (source)

Clears the inference cache.

def parse(self, source, modname, *, is_package=False, **kw): (source)

Parse the python source string into a ast.Module instance, and make compatible with astuce inference system.

source
The python code string.
modname
The full name of the module, required. This additional argument is the only breaking changed compared to ast.parse.
is_package
Whether this module is package.
kw

Other arguments are passed to the ast.parse function directly. Including:

  • filename: The filename where we can find the module source
    (only used for error messages)
Parameters
source:strUndocumented
modname:strUndocumented
is_package:boolUndocumented
**kw:AnyUndocumented
Returns
_typing.ModuleUndocumented
Unknown Field: newfield
parameters

Parameters

Unknown Field: parameters
def unparse(self, node): (source)

Unparse an ast.AST object and generate a code string.

Parameters
node:ast.ASTUndocumented
Returns
strUndocumented
max_inferable_values: int = (source)

Undocumented

The parsed modules.

def _init_new_node(self, node, parent): (source)

A method that must be called for all nodes in the tree as well as inferred (created) nodes.

Parameters
node:ASTNodeUndocumented
parent:ASTNodeUndocumented
def _new_context(self): (source)

Create a fresh inference context.

Returns
_context.InferenceContextUndocumented

A list to store assignments to attributes.

We might want to resolve them after building.

Inferred node contexts to their mapped results.

The keys are nodes and the value is tuple of the inferred results.

See Also
InferenceContext._cache
_wildcard_import: List[_typing.ImportFrom] = (source)

Store wildcard ImportFrom to resolve them after building.