[pypy-svn] r58961 - in pypy/branch/2.5-merge/pypy: interpreter interpreter/test module/__builtin__

arigo at codespeak.net arigo at codespeak.net
Sat Oct 11 13:05:31 CEST 2008


Author: arigo
Date: Sat Oct 11 13:05:31 2008
New Revision: 58961

Modified:
   pypy/branch/2.5-merge/pypy/interpreter/pyopcode.py
   pypy/branch/2.5-merge/pypy/interpreter/test/test_compiler.py
   pypy/branch/2.5-merge/pypy/interpreter/test/test_exec.py
   pypy/branch/2.5-merge/pypy/module/__builtin__/compiling.py
Log:
(antocuni, arigo)
Add tests that correspond to removing code :-)

This cancels rev 11877, which was a hack for CPython compliance.
It turns out that CPython 2.5 changed.



Modified: pypy/branch/2.5-merge/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/branch/2.5-merge/pypy/interpreter/pyopcode.py	(original)
+++ pypy/branch/2.5-merge/pypy/interpreter/pyopcode.py	Sat Oct 11 13:05:31 2008
@@ -1348,15 +1348,7 @@
                 else:
                     raise TypeError("exec: arg 1 must be a string, file, "
                                     "or code object")
-            try:
-                prog = compile(prog, filename, 'exec', compile_flags, 1)
-            except SyntaxError, e: # exec SyntaxErrors have filename==None
-               if len(e.args) == 2:
-                   msg, loc = e.args
-                   loc1 = (None,) + loc[1:]
-                   e.args = msg, loc1
-                   e.filename = None
-               raise e
+            prog = compile(prog, filename, 'exec', compile_flags, 1)
         return (prog, globals, locals)
 ''', filename=__file__)
 

Modified: pypy/branch/2.5-merge/pypy/interpreter/test/test_compiler.py
==============================================================================
--- pypy/branch/2.5-merge/pypy/interpreter/test/test_compiler.py	(original)
+++ pypy/branch/2.5-merge/pypy/interpreter/test/test_compiler.py	Sat Oct 11 13:05:31 2008
@@ -581,6 +581,15 @@
         """)
         assert space.float_w(w_result) == 0
 
+    def test_filename_in_syntaxerror(self):
+        e = py.test.raises(OperationError, self.compiler.compile, """if 1:
+            'unmatched_quote
+            """, 'hello_world', 'exec', 0)
+        ex = e.value
+        space = self.space
+        assert ex.match(space, space.w_SyntaxError)
+        assert 'hello_world' in space.str_w(space.str(ex.w_value))
+
 
 class TestPyCCompiler(BaseTestCompiler):
     def setup_method(self, method):

Modified: pypy/branch/2.5-merge/pypy/interpreter/test/test_exec.py
==============================================================================
--- pypy/branch/2.5-merge/pypy/interpreter/test/test_exec.py	(original)
+++ pypy/branch/2.5-merge/pypy/interpreter/test/test_exec.py	Sat Oct 11 13:05:31 2008
@@ -192,3 +192,12 @@
         exec "y=n" in m   # NOTE: this doesn't work in CPython 2.4
         assert m.result == {'x': 'm', 'y': 'n'}
 
+    def test_filename(self):
+        try:
+            exec "'unmatched_quote"
+        except SyntaxError, msg:
+            assert msg.filename == '<string>'
+        try:
+            eval("'unmatched_quote")
+        except SyntaxError, msg:
+            assert msg.filename == '<string>'

Modified: pypy/branch/2.5-merge/pypy/module/__builtin__/compiling.py
==============================================================================
--- pypy/branch/2.5-merge/pypy/module/__builtin__/compiling.py	(original)
+++ pypy/branch/2.5-merge/pypy/module/__builtin__/compiling.py	Sat Oct 11 13:05:31 2008
@@ -60,22 +60,10 @@
 
     if (space.is_true(space.isinstance(w_code, space.w_str)) or
         space.is_true(space.isinstance(w_code, space.w_unicode))):
-        try:
-            w_code = compile(space,
-                             space.call_method(w_code, 'lstrip',
-                                               space.wrap(' \t')),
-                             "<string>", "eval")
-        except OperationError, e:
-            if e.match(space, space.w_SyntaxError):
-                e_value_w = space.viewiterable(e.w_value)
-                if len(e_value_w) == 2:
-                    e_loc_w = space.viewiterable(e_value_w[1])
-                    e.w_value = space.newtuple([e_value_w[0],
-                                                space.newtuple([space.w_None]+
-                                                               e_loc_w[1:])])
-                raise e
-            else:
-                raise
+        w_code = compile(space,
+                         space.call_method(w_code, 'lstrip',
+                                           space.wrap(' \t')),
+                         "<string>", "eval")
 
     codeobj = space.interpclass_w(w_code)
     if not isinstance(codeobj, PyCode):



More information about the Pypy-commit mailing list