Bring Tools/compiler almost up to date. Specifically:
- fix tab space issues (SF patch #101167 by Neil Schemenauer)
- fix co_flags for classes to include CO_NEWLOCALS (SF patch #101145 by Neil)
- fix for merger of UNPACK_LIST and UNPACK_TUPLE into UNPACK_SEQUENCE,
(SF patch #101168 by, well, Neil :)
- Adjust bytecode MAGIC to current bytecode.
TODO: teach compile.py about list comprehensions.
diff --git a/Lib/compiler/visitor.py b/Lib/compiler/visitor.py
index d0e5223..32e72e1 100644
--- a/Lib/compiler/visitor.py
+++ b/Lib/compiler/visitor.py
@@ -38,7 +38,7 @@
def __init__(self):
self.node = None
- self._cache = {}
+ self._cache = {}
def preorder(self, tree, visitor):
"""Do preorder walk of tree using visitor"""
@@ -47,7 +47,7 @@
self._preorder(tree)
def _preorder(self, node, *args):
- return apply(self.dispatch, (node,) + args)
+ return apply(self.dispatch, (node,) + args)
def default(self, node, *args):
for child in node.getChildren():
@@ -56,18 +56,18 @@
def dispatch(self, node, *args):
self.node = node
- meth = self._cache.get(node.__class__, None)
- className = node.__class__.__name__
- if meth is None:
- meth = getattr(self.visitor, 'visit' + className, self.default)
- self._cache[node.__class__] = meth
+ meth = self._cache.get(node.__class__, None)
+ className = node.__class__.__name__
+ if meth is None:
+ meth = getattr(self.visitor, 'visit' + className, self.default)
+ self._cache[node.__class__] = meth
if self.VERBOSE > 0:
if self.VERBOSE == 1:
if meth == 0:
print "dispatch", className
else:
print "dispatch", className, (meth and meth.__name__ or '')
- return apply(meth, (node,) + args)
+ return apply(meth, (node,) + args)
class ExampleASTVisitor(ASTVisitor):
"""Prints examples of the nodes that aren't visited
@@ -80,11 +80,11 @@
def dispatch(self, node, *args):
self.node = node
- meth = self._cache.get(node.__class__, None)
- className = node.__class__.__name__
- if meth is None:
- meth = getattr(self.visitor, 'visit' + className, 0)
- self._cache[node.__class__] = meth
+ meth = self._cache.get(node.__class__, None)
+ className = node.__class__.__name__
+ if meth is None:
+ meth = getattr(self.visitor, 'visit' + className, 0)
+ self._cache[node.__class__] = meth
if self.VERBOSE > 1:
print "dispatch", className, (meth and meth.__name__ or '')
if meth:
@@ -92,15 +92,15 @@
elif self.VERBOSE > 0:
klass = node.__class__
if not self.examples.has_key(klass):
- self.examples[klass] = klass
- print
- print self.visitor
- print klass
- for attr in dir(node):
- if attr[0] != '_':
- print "\t", "%-12.12s" % attr, getattr(node, attr)
- print
- return apply(self.default, (node,) + args)
+ self.examples[klass] = klass
+ print
+ print self.visitor
+ print klass
+ for attr in dir(node):
+ if attr[0] != '_':
+ print "\t", "%-12.12s" % attr, getattr(node, attr)
+ print
+ return apply(self.default, (node,) + args)
_walker = ASTVisitor
def walk(tree, visitor, verbose=None):