module documentation

Undocumented

Class CollectLocals Undocumented
Function collect_future_imports Returns a set of future imports names for the given ast module.
Function collect_locals Compute the set of identifiers local to a given node.
Function lookup_annotation_name_defs Simple identifier -> defs resolving.
Function pkg Given a supported AST node, return the origin module where it's class is defined. The result will be gast or ast.
Variable Builtins Undocumented
Variable DeclarationStep Undocumented
Variable DefinitionStep Undocumented
Class _CollectFutureImports Undocumented
Exception _StopTraversal Undocumented
Function _get_lookup_scopes Undocumented
Function _iter_arguments Yields all arguments of the given ast.arguments instance.
Function _lookup Undocumented
Function _rename_attrs Provide cheap attribute polymorphism.
Function _validate_comprehension Undocumented
Variable _novalue Undocumented
def collect_future_imports(node): (source)

Returns a set of future imports names for the given ast module.

def collect_locals(node): (source)

Compute the set of identifiers local to a given node.

This is meant to emulate a call to locals()

def lookup_annotation_name_defs(name, heads, locals_map): (source)

Simple identifier -> defs resolving.

Lookup a name with the provided head nodes using the locals_map. Note that nonlocal and global keywords are ignored by this function. Only used to resolve annotations when PEP 563 is enabled.

This function can be used by client code like this:

>>> import gast as ast
>>> module = ast.parse("from b import c;import typing as t\nclass C:\n def f(self):self.var = c.Thing()")
>>> duc = DefUseChains()
>>> duc.visit(module)
>>> ancestors = Ancestors()
>>> ancestors.visit(module)
... # we're placing ourselves in the context of the function body
>>> fn_scope = module.body[-1].body[-1]
>>> assert isinstance(fn_scope, ast.FunctionDef)
>>> heads = ancestors.parents(fn_scope) + [fn_scope]
>>> print(lookup_annotation_name_defs('t', heads, duc.locals)[0])
t -> ()
>>> print(lookup_annotation_name_defs('c', heads, duc.locals)[0])
c -> (c -> (.Thing -> (<Call> -> ())))
>>> print(lookup_annotation_name_defs('C', heads, duc.locals)[0])
C -> ()
Parameters
nameThe identifier we're looking up.
headsList of ast scope statement that describe the path to the name context. i.e [<Module>, <ClassDef>, <FunctionDef>]. The lookup will happend in the context of the body of tail of heads Can be gathered with Ancestors.parents.
locals_mapDefUseChains.locals.
Raises
LookupErrorFor - builtin names - wildcard imported names - unbound names
ValueErrorWhen the heads is empty.
def pkg(node): (source)

Given a supported AST node, return the origin module where it's class is defined. The result will be gast or ast.

Builtins = (source)

Undocumented

DeclarationStep = (source)

Undocumented

DefinitionStep = (source)

Undocumented

def _get_lookup_scopes(heads): (source)

Undocumented

def _iter_arguments(args): (source)

Yields all arguments of the given ast.arguments instance.

def _lookup(name, scopes, locals_map): (source)

Undocumented

def _rename_attrs(obj, **attrs): (source)

Provide cheap attribute polymorphism.

def _validate_comprehension(node): (source)

Undocumented

_novalue = (source)

Undocumented