2012-06-30 | Paul Boddie | raw annotate files changeset graph | Added imported name storage (necessary where such names are not constant). Made a convenience method for storing working values as local names. Removed instance-related code where guards test for module types. Changed the _generateName method to perform scope discovery internally. |
1 #!/usr/bin/env python 2 3 class C: 4 def __init__(self): 5 self.visitor = self 6 7 def default(self, node): 8 return 123 9 10 def dispatch(self, node): 11 try: 12 return node.visit(self.visitor) 13 except AttributeError: 14 return self.visitor.default(node) 15 16 class N: 17 def visit(self, visitor): 18 return 456 19 20 c = C() 21 n = N() 22 result_456 = c.dispatch(n) 23 24 # vim: tabstop=4 expandtab shiftwidth=4