Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r59388:1fa955dea1aa
Date: 2012-12-10 13:47 -0800
http://bitbucket.org/pypy/pypy/changeset/1fa955dea1aa/

Log:    stricter type checks for eval

diff --git a/pypy/interpreter/test/test_exec.py 
b/pypy/interpreter/test/test_exec.py
--- a/pypy/interpreter/test/test_exec.py
+++ b/pypy/interpreter/test/test_exec.py
@@ -143,6 +143,7 @@
             pass
         else:
             assert False, 'Expected TypeError'
+        raises(TypeError, eval, "m", m)
 
     def test_filename(self):
         try:
diff --git a/pypy/module/__builtin__/compiling.py 
b/pypy/module/__builtin__/compiling.py
--- a/pypy/module/__builtin__/compiling.py
+++ b/pypy/module/__builtin__/compiling.py
@@ -3,7 +3,7 @@
 """
 
 from pypy.interpreter.pycode import PyCode
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, operationerrfmt
 from pypy.interpreter.astcompiler import consts, ast
 from pypy.interpreter.gateway import unwrap_spec
 from pypy.interpreter.argument import Arguments
@@ -85,6 +85,7 @@
     is_unicode = space.is_true(space.isinstance(w_code, space.w_unicode))
     if (is_unicode or space.is_true(space.isinstance(w_code, space.w_bytes))):
         w_strip = w(u' \t') if is_unicode else space.wrapbytes(' \t')
+        # XXX: w_code.lstrip could be overriden
         w_code = compile(space, space.call_method(w_code, 'lstrip', w_strip),
                          "<string>", "eval")
 
@@ -93,6 +94,17 @@
         raise OperationError(space.w_TypeError,
               w('eval() arg 1 must be a string or code object'))
 
+    if (not space.is_none(w_globals) and
+        not space.isinstance_w(w_globals, space.w_dict)):
+        raise operationerrfmt(space.w_TypeError,
+                              'eval() arg 2 must be a dict, not %s',
+                              space.type(w_globals).getname(space))
+    if (not space.is_none(w_locals) and
+        space.lookup(w_locals, '__getitem__') is None):
+        raise operationerrfmt(space.w_TypeError,
+                              'eval() arg 3 must be a mapping or None, not %s',
+                              space.type(w_locals).getname(space))
+
     if space.is_none(w_globals):
         caller = space.getexecutioncontext().gettopframe_nohidden()
         if caller is None:
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to