[pypy-svn] r66261 - in pypy/branch/parser-compiler/pypy/interpreter: astcompiler/tools test

benjamin at codespeak.net benjamin at codespeak.net
Thu Jul 16 00:05:34 CEST 2009


Author: benjamin
Date: Thu Jul 16 00:05:33 2009
New Revision: 66261

Modified:
   pypy/branch/parser-compiler/pypy/interpreter/astcompiler/tools/asdl_py.py
   pypy/branch/parser-compiler/pypy/interpreter/test/test_compiler.py
Log:
add a default method for unimplemented visitor methods

Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/tools/asdl_py.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/tools/asdl_py.py	(original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/tools/asdl_py.py	Thu Jul 16 00:05:33 2009
@@ -105,6 +105,9 @@
         self.emit("for node in seq:", 2)
         self.emit("node.walkabout(self)", 3)
         self.emit("")
+        self.emit("def default_visitor(self, node):", 1)
+        self.emit("raise NodeVisitorNotImplemented", 2)
+        self.emit("")
         super(ASTVisitorVisitor, self).visitModule(mod)
         self.emit("")
 
@@ -115,11 +118,11 @@
 
     def visitProduct(self, prod, name):
         self.emit("def visit_%s(self, node):" % (name,), 1)
-        self.emit("raise NodeVisitorNotImplemented", 2)
+        self.emit("self.default_visitor(node)", 2)
 
     def visitConstructor(self, cons, _):
         self.emit("def visit_%s(self, node):" % (cons.name,), 1)
-        self.emit("raise NodeVisitorNotImplemented", 2)
+        self.emit("self.default_visitor(node)", 2)
 
 
 class GenericASTVisitorVisitor(ASDLVisitor):

Modified: pypy/branch/parser-compiler/pypy/interpreter/test/test_compiler.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/test/test_compiler.py	(original)
+++ pypy/branch/parser-compiler/pypy/interpreter/test/test_compiler.py	Thu Jul 16 00:05:33 2009
@@ -197,21 +197,25 @@
             assert not space.eq_w(w_const, space.wrap("b"))
             assert not space.eq_w(w_const, space.wrap("c"))
 
+    _unicode_error_kind = "w_UnicodeError"
+
     def test_unicodeliterals(self):
+        w_error = getattr(self.space, self._unicode_error_kind)
+
         e = py.test.raises(OperationError, self.eval_string, "u'\\Ufffffffe'")
         ex = e.value
         ex.normalize_exception(self.space)
-        assert ex.match(self.space, self.space.w_UnicodeError)
+        assert ex.match(self.space, w_error)
 
         e = py.test.raises(OperationError, self.eval_string, "u'\\Uffffffff'")
         ex = e.value
         ex.normalize_exception(self.space)
-        assert ex.match(self.space, self.space.w_UnicodeError)
+        assert ex.match(self.space, w_error)
 
         e = py.test.raises(OperationError, self.eval_string, "u'\\U%08x'" % 0x110000)
         ex = e.value
         ex.normalize_exception(self.space)
-        assert ex.match(self.space, self.space.w_UnicodeError)
+        assert ex.match(self.space, w_error)
 
     def test_unicode_docstring(self):
         space = self.space
@@ -637,6 +641,8 @@
     def setup_method(self, method):
         self.compiler = CPythonCompiler(self.space)
 
+    _unicode_error_kind = "w_SyntaxError"
+
     if sys.version_info < (2, 4):
         def skip_on_2_3(self):
             py.test.skip("syntax not supported by the CPython 2.3 compiler")



More information about the Pypy-commit mailing list