[pypy-svn] r77670 - in pypy/branch/fast-forward: lib-python pypy/module/__builtin__ pypy/module/__builtin__/test

afa at codespeak.net afa at codespeak.net
Wed Oct 6 23:59:24 CEST 2010


Author: afa
Date: Wed Oct  6 23:59:18 2010
New Revision: 77670

Modified:
   pypy/branch/fast-forward/lib-python/TODO
   pypy/branch/fast-forward/pypy/module/__builtin__/compiling.py
   pypy/branch/fast-forward/pypy/module/__builtin__/test/test_builtin.py
Log:
Fix eval('a', None, dict(a=42))


Modified: pypy/branch/fast-forward/lib-python/TODO
==============================================================================
--- pypy/branch/fast-forward/lib-python/TODO	(original)
+++ pypy/branch/fast-forward/lib-python/TODO	Wed Oct  6 23:59:18 2010
@@ -12,10 +12,6 @@
 
 - Missing builtin: bytearray (possibly reuse module.__pypy__.bytebuffer)
 
-- Seen in test_inspect, this has never worked in pypy::
-
-      assert eval('a', None, dict(a=42)) == 42
-
 - Missing complex.__trunc__
 
 - Mark some tests as "implementation specific"::

Modified: pypy/branch/fast-forward/pypy/module/__builtin__/compiling.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/__builtin__/compiling.py	(original)
+++ pypy/branch/fast-forward/pypy/module/__builtin__/compiling.py	Wed Oct  6 23:59:18 2010
@@ -65,7 +65,7 @@
 compile.unwrap_spec = [ObjSpace,W_Root,str,str,int,int]
 
 
-def eval(space, w_code, w_globals=NoneNotWrapped, w_locals=NoneNotWrapped):
+def eval(space, w_code, w_globals=None, w_locals=None):
     """Evaluate the source in the context of globals and locals.
 The source may be a string representing a Python expression
 or a code object as returned by compile().  The globals and locals
@@ -87,13 +87,16 @@
               w('eval() arg 1 must be a string or code object'))
 
     caller = space.getexecutioncontext().gettopframe_nohidden()
-    if w_globals is None or space.is_w(w_globals, space.w_None): 
+    if space.is_w(w_globals, space.w_None):
         if caller is None:
-            w_globals = w_locals = space.newdict()
+            w_globals = space.newdict()
+            if space.is_w(w_locals, space.w_None):
+                w_locals = w_globals
         else:
             w_globals = caller.w_globals
-            w_locals = caller.getdictscope()
-    elif w_locals is None:
+            if space.is_w(w_locals, space.w_None):
+                w_locals = caller.getdictscope()
+    elif space.is_w(w_locals, space.w_None):
         w_locals = w_globals
 
     try:

Modified: pypy/branch/fast-forward/pypy/module/__builtin__/test/test_builtin.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/__builtin__/test/test_builtin.py	(original)
+++ pypy/branch/fast-forward/pypy/module/__builtin__/test/test_builtin.py	Wed Oct  6 23:59:18 2010
@@ -432,6 +432,7 @@
         assert eval("3", None, None) == 3
         i = 4
         assert eval("i", None, None) == 4
+        assert eval('a', None, dict(a=42)) == 42
 
     def test_compile(self):
         co = compile('1+2', '?', 'eval')



More information about the Pypy-commit mailing list