module documentation
Undocumented
| Class | |
Undocumented |
| Function | collect |
Returns a set of future imports names for the given ast module. |
| Function | collect |
Compute the set of identifiers local to a given node. |
| Function | lookup |
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 | |
Undocumented |
| Variable | |
Undocumented |
| Variable | |
Undocumented |
| Class | _ |
Undocumented |
| Exception | _ |
Undocumented |
| Function | _get |
Undocumented |
| Function | _iter |
Yields all arguments of the given ast.arguments instance. |
| Function | _lookup |
Undocumented |
| Function | _rename |
Provide cheap attribute polymorphism. |
| Function | _validate |
Undocumented |
| Variable | _novalue |
Undocumented |
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 | |
| name | The identifier we're looking up. |
| heads | List 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 | DefUseChains.locals. |
| Raises | |
LookupError | For - builtin names - wildcard imported names - unbound names |
ValueError | When the heads is empty. |