[pypy-commit] pypy py3.5: compile() now raises ValueError, not TypeError, when the source contains null bytes

rlamy pypy.commits at gmail.com
Wed Nov 2 13:53:29 EDT 2016


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3.5
Changeset: r88089:eebb8cd4bece
Date: 2016-11-02 17:52 +0000
http://bitbucket.org/pypy/pypy/changeset/eebb8cd4bece/

Log:	compile() now raises ValueError, not TypeError, when the source
	contains null bytes

diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -1819,7 +1819,7 @@
 
     if not (flags & consts.PyCF_ACCEPT_NULL_BYTES):
         if '\x00' in source:
-            raise oefmt(space.w_TypeError,
+            raise oefmt(space.w_ValueError,
                         "source code string cannot contain null bytes")
         source = rstring.assert_str0(source)
     return source, flags
diff --git a/pypy/module/__builtin__/test/test_builtin.py b/pypy/module/__builtin__/test/test_builtin.py
--- a/pypy/module/__builtin__/test/test_builtin.py
+++ b/pypy/module/__builtin__/test/test_builtin.py
@@ -502,7 +502,7 @@
         assert eval(co) == 3
         co = compile(memoryview(b'1+2'), '?', 'eval')
         assert eval(co) == 3
-        exc = raises(TypeError, compile, chr(0), '?', 'eval')
+        exc = raises(ValueError, compile, chr(0), '?', 'eval')
         assert str(exc.value) == "source code string cannot contain null bytes"
         compile("from __future__ import with_statement", "<test>", "exec")
         raises(SyntaxError, compile, '-', '?', 'eval')
@@ -646,10 +646,10 @@
         assert firstlineno == 2
 
     def test_compile_null_bytes(self):
-        raises(TypeError, compile, '\x00', 'mymod', 'exec', 0)
+        raises(ValueError, compile, '\x00', 'mymod', 'exec', 0)
         src = "#abc\x00def\n"
-        raises(TypeError, compile, src, 'mymod', 'exec')
-        raises(TypeError, compile, src, 'mymod', 'exec', 0)
+        raises(ValueError, compile, src, 'mymod', 'exec')
+        raises(ValueError, compile, src, 'mymod', 'exec', 0)
 
     def test_compile_null_bytes_flag(self):
         try:


More information about the pypy-commit mailing list