PyDocs

Nav

Python Language Services

NodeVisitor

ast

class (source) Deprecated 3.8
Deprecated since 3.8, removed in 3.14. Methods visit_Num(), visit_Str(), visit_Bytes(), visit_NameConstant() and visit_Ellipsis() will not be called in Python 3.14+. Add the visit_Constant() method instead to handle all constant nodes.
A node visitor base class that walks the abstract syntax tree and calls a
visitor function for every node found.  This function may return a value
which is forwarded by the `visit` method.

This class is meant to be subclassed, with the subclass adding visitor
methods.

Per default the visitor functions for the nodes are ``'visit_'`` +
class name of the node.  So a `TryFinally` node visit function would
be `visit_TryFinally`.  This behavior can be changed by overriding
the `visit` method.  If no visitor function exists for a node
(return value `None`) the `generic_visit` visitor is used instead.

Don't use the `NodeVisitor` if you want to apply changes to nodes during
traversing.  For this a special visitor exists (`NodeTransformer`) that
allows modifications.
Members of NodeVisitor

g

generic_visit
Called if no explicit visitor function exists for a node.

v

visit
Visit a node.
visit_Constant
Handles all constant nodes.
0 Examples
No examples for ast/NodeVisitor.
See Also
No see-alsos for ast/NodeVisitor
0 Notes
No notes for NodeVisitor