[pypy-svn] r50468 - in pypy/branch/astcompilertests/pypy/interpreter/astcompiler: . test

arigo at codespeak.net arigo at codespeak.net
Wed Jan 9 20:10:20 CET 2008


Author: arigo
Date: Wed Jan  9 20:10:19 2008
New Revision: 50468

Modified:
   pypy/branch/astcompilertests/pypy/interpreter/astcompiler/pycodegen.py
   pypy/branch/astcompilertests/pypy/interpreter/astcompiler/test/test_compiler.py
Log:
Test and fix for lib-python's test_trace.


Modified: pypy/branch/astcompilertests/pypy/interpreter/astcompiler/pycodegen.py
==============================================================================
--- pypy/branch/astcompilertests/pypy/interpreter/astcompiler/pycodegen.py	(original)
+++ pypy/branch/astcompilertests/pypy/interpreter/astcompiler/pycodegen.py	Wed Jan  9 20:10:19 2008
@@ -860,7 +860,7 @@
         self.loadName(node.varname, node.lineno)
 
     def visitPass(self, node):
-        self.set_lineno(node)
+        pass  # no self.set_lineno(node) unnecessarily! see test_return_lineno
 
     def visitImport(self, node):
         self.set_lineno(node)

Modified: pypy/branch/astcompilertests/pypy/interpreter/astcompiler/test/test_compiler.py
==============================================================================
--- pypy/branch/astcompilertests/pypy/interpreter/astcompiler/test/test_compiler.py	(original)
+++ pypy/branch/astcompilertests/pypy/interpreter/astcompiler/test/test_compiler.py	Wed Jan  9 20:10:19 2008
@@ -425,6 +425,24 @@
                 comment = ''
         """, 'comments', ['# foo', 42]
 
+    def test_return_lineno(self):
+        # the point of this test is to check that there is no code associated
+        # with any line greater than 4.  The implicit return should not have
+        # any line number - otherwise it would probably show up at line 5,
+        # which is confusing because it's in the wrong branch of the "if"
+        # in the case where a == b.
+        yield self.simple_test, """\
+            def ireturn_example():    # line 1
+                global b              # line 2
+                if a == b:            # line 3
+                    b = a+1           # line 4
+                else:                 # line 5
+                    if 1: pass        # line 6
+            import dis
+            co = ireturn_example.func_code
+            x = [lineno for addr, lineno in dis.findlinestarts(co)]
+        """, 'x', [3, 4]
+
     def test_pprint(self):
         # a larger example that showed a bug with jumps
         # over more than 256 bytes


More information about the pypy-svn mailing list