API Reference#
- class NodeWalk(node: AST)[source]#
A class for exploring definitions in an AST.
- Parameters:
node – The root AST node.
- classmethod from_source(source: str) NodeWalk[source]#
Create a
NodeWalkobject from python source code. The code is parsed using the built-inastmodule.
- classmethod from_file(filename: str) NodeWalk[source]#
Create a
NodeWalkobject from a python file. The file is read as text and parsed using the built-inastmodule.
- children() Mapping[str, Sequence[NodeWalk]][source]#
Returns a mapping of the names of the named declared in the node to a sequence of
NodeWalkobjects for each declaration.
- __getitem__(name: str) NodeWalk[source]#
Returns a
NodeWalkobject for the declaration of the given name.- Parameters:
name – The name of the declared object. Can also be a dotted name.
- Raises:
KeyError – If the name is not declared in the node.
ValueError – If the node declares multiple names with the given name.
- get_last(name: str) NodeWalk[source]#
Returns a
NodeWalkobject for the last declaration of the given name.- Parameters:
name – The name of the declared object. Can also be a dotted name.
- Raises:
KeyError – If the name is not declared in the node.
- get_many(name: str) Sequence[NodeWalk][source]#
Returns a sequence of
NodeWalkobjects for each declaration of the given name. If the name is not declared in the node, an empty sequence is returned.