Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
ast.NodeVisitor Class Reference
Inheritance diagram for ast.NodeVisitor:
Inheritance graph
Collaboration diagram for ast.NodeVisitor:
Collaboration graph

List of all members.

Public Member Functions

def visit
def generic_visit

Public Attributes

_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Detailed Description

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

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.

Definition at line 224 of file

Member Function Documentation

def ast.NodeVisitor.generic_visit (   self,
Called if no explicit visitor function exists for a node.

Reimplemented in ast.NodeTransformer.

Definition at line 250 of file

00251     def generic_visit(self, node):
00252         """Called if no explicit visitor function exists for a node."""
00253         for field, value in iter_fields(node):
00254             if isinstance(value, list):
00255                 for item in value:
00256                     if isinstance(item, AST):
00257                         self.visit(item)
00258             elif isinstance(value, AST):
00259                 self.visit(value)

Here is the call graph for this function:

Here is the caller graph for this function:

def ast.NodeVisitor.visit (   self,
Visit a node.

Definition at line 244 of file

00245     def visit(self, node):
00246         """Visit a node."""
00247         method = 'visit_' + node.__class__.__name__
00248         visitor = getattr(self, method, self.generic_visit)
00249         return visitor(node)

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

The documentation for this class was generated from the following file: