[pypy-svn] r19138 - in pypy/dist/pypy/interpreter: . test

pedronis at codespeak.net pedronis at codespeak.net
Sat Oct 29 01:35:33 CEST 2005


Author: pedronis
Date: Sat Oct 29 01:35:30 2005
New Revision: 19138

Modified:
   pypy/dist/pypy/interpreter/function.py
   pypy/dist/pypy/interpreter/test/test_function.py
Log:
reject None as closure parameter if the code wants a closure.

make compliancy test_new pass again.



Modified: pypy/dist/pypy/interpreter/function.py
==============================================================================
--- pypy/dist/pypy/interpreter/function.py	(original)
+++ pypy/dist/pypy/interpreter/function.py	Sat Oct 29 01:35:30 2005
@@ -63,7 +63,8 @@
             defs_w = space.unpackiterable(w_argdefs)
         else:
             defs_w = []
-        if space.is_w(w_closure, space.w_None):
+        nfreevars = len(code.co_freevars)
+        if space.is_w(w_closure, space.w_None) and nfreevars == 0:
             closure = None
         elif not space.is_w(space.type(w_closure), space.w_tuple):
             raise OperationError(space.w_TypeError, space.wrap("invalid closure"))
@@ -72,9 +73,9 @@
             from pypy.interpreter.nestedscope import Cell
             closure_w = space.unpackiterable(w_closure)
             n = len(closure_w)
-            if not isinstance(code, PyCode) or len(code.co_freevars) == 0:
+            if not isinstance(code, PyCode) or nfreevars == 0:
                 raise OperationError(space.w_ValueError, space.wrap("no closure needed"))
-            elif len(code.co_freevars) != n:
+            elif nfreevars != n:
                 raise OperationError(space.w_ValueError, space.wrap("closure is wrong size"))
             closure = []
             for w_cell in closure_w:

Modified: pypy/dist/pypy/interpreter/test/test_function.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_function.py	(original)
+++ pypy/dist/pypy/interpreter/test/test_function.py	Sat Oct 29 01:35:30 2005
@@ -61,6 +61,13 @@
         f2 = FuncType(f.func_code, f.func_globals, 'f2', None, None)
         assert f2() == 42
 
+        def g(x):
+            def f():
+                return x
+            return f
+        f = g(42)
+        raises(TypeError, FuncType, f.func_code, f.func_globals, 'f2', None, None)
+
 class AppTestFunction: 
     def test_simple_call(self):
         def func(arg1, arg2):



More information about the Pypy-commit mailing list