[Compiler-sig] proposed change to compiler package

Jeremy Hylton jeremy at alum.mit.edu
Fri Oct 31 14:44:08 EST 2003

The top-level walk() function in the compiler package returns the
visitor object that is passed to walk.  I'd like to change it to return
the result of the top-level dispatch() or visit() call.  Right now,
visitor methods can return a value, which is useful for a visit() call
that is internal to a visitor, but can't return it to the caller of

The current return value is pretty useless, since the caller of walk()
must pass the visitor as one of the arguments.  That is, walk() returns
one of its arguments.  The change might break some code, but only in a
trivial way, and it will make possible to write visitors that don't have
any state-- simple combinators.


class NameVisitor:
    """Compute a dotted name from an expression."""

    def visitGetattr(self, node):
        return "%s.%s" % (self.visit(node.expr), node.attrname)

    def visitName(self, node):
        return node.name


More information about the Compiler-sig mailing list