[pypy-svn] r14145 - in pypy/branch/dist-2.4.1: lib-python/modified-2.4.1/test pypy/interpreter

quest at codespeak.net quest at codespeak.net
Sun Jul 3 16:23:28 CEST 2005


Author: quest
Date: Sun Jul  3 16:23:27 2005
New Revision: 14145

Added:
   pypy/branch/dist-2.4.1/lib-python/modified-2.4.1/test/test_funcattrs.py
      - copied, changed from r14137, pypy/branch/dist-2.4.1/lib-python/2.4.1/test/test_funcattrs.py
Modified:
   pypy/branch/dist-2.4.1/pypy/interpreter/function.py
   pypy/branch/dist-2.4.1/pypy/interpreter/typedef.py
Log:
Adapted to two changes in cpython 2.4.1: 1) function objects can now
have their __name__ (and func_name) modified. 2) function objects can
only have their func_code replaced with another code object with the
same number of co_freevars.


Copied: pypy/branch/dist-2.4.1/lib-python/modified-2.4.1/test/test_funcattrs.py (from r14137, pypy/branch/dist-2.4.1/lib-python/2.4.1/test/test_funcattrs.py)
==============================================================================
--- pypy/branch/dist-2.4.1/lib-python/2.4.1/test/test_funcattrs.py	(original)
+++ pypy/branch/dist-2.4.1/lib-python/modified-2.4.1/test/test_funcattrs.py	Sun Jul  3 16:23:27 2005
@@ -36,8 +36,8 @@
 
 try:
     del b.__dict__
-except TypeError: pass
-else: raise TestFailed, 'del func.__dict__ expected TypeError'
+except (AttributeError, TypeError): pass
+else: raise TestFailed, 'expected AttributeError or TypeError'
 
 b.publish = 1
 try:
@@ -175,13 +175,13 @@
 
 try:
     del another.__dict__
-except TypeError: pass
-else: raise TestFailed
+except (TypeError, AttributeError): pass
+else: raise TestFailed, 'del another.__dict__ did not fail'
 
 try:
     del another.func_dict
-except TypeError: pass
-else: raise TestFailed
+except (TypeError, AttributeError): pass
+else: raise TestFailed, 'del another.func_dict did not fail'
 
 try:
     another.func_dict = None

Modified: pypy/branch/dist-2.4.1/pypy/interpreter/function.py
==============================================================================
--- pypy/branch/dist-2.4.1/pypy/interpreter/function.py	(original)
+++ pypy/branch/dist-2.4.1/pypy/interpreter/function.py	Sun Jul  3 16:23:27 2005
@@ -115,6 +115,20 @@
     def fset_func_doc(space, self, w_doc):
         self.w_doc = w_doc
 
+    def fget_func_name(space, self):
+        return space.wrap(self.name)
+
+    def fset_func_name(space, self, w_name):
+        try:
+            self.name = space.str_w(w_name)
+        except OperationError, e:
+            if e.match(space, space.w_TypeError):
+                raise OperationError(space.w_TypeError,
+                                     space.wrap("func_name must be set "
+                                                "to a string object"))
+            raise
+
+
     def fdel_func_doc(space, self):
         self.w_doc = space.w_None
 
@@ -137,8 +151,10 @@
 
     def fset_func_code(space, self, w_code):
         code = space.interpclass_w(w_code)
-        if not isinstance(code, Code ):
-            raise OperationError( space.w_TypeError, space.wrap("func_code must be set to a code object") )
+        if not isinstance(code, Code):
+            raise OperationError(space.w_TypeError, space.wrap("func_code must be set to a code object") )
+        if len(self.code.co_freevars) != len(code.co_freevars):
+            raise OperationError(space.w_ValueError, space.wrap("%s() requires a code object with %s free vars, not %s " % (self.name, len(self.code.co_freevars), len(code.co_freevars))))
         self.code = code
 
     def fget_func_closure(space, self):

Modified: pypy/branch/dist-2.4.1/pypy/interpreter/typedef.py
==============================================================================
--- pypy/branch/dist-2.4.1/pypy/interpreter/typedef.py	(original)
+++ pypy/branch/dist-2.4.1/pypy/interpreter/typedef.py	Sun Jul  3 16:23:27 2005
@@ -430,6 +430,8 @@
                                       Function.fdel_func_defaults)
 getset_func_code = GetSetProperty(Function.fget_func_code,
                                   Function.fset_func_code)
+getset_func_name = GetSetProperty(Function.fget_func_name,
+                                  Function.fset_func_name)
 
 getset_func_dict = GetSetProperty(descr_get_dict, descr_set_dict, cls=Function)
 
@@ -441,13 +443,13 @@
     __repr__ = interp2app(Function.descr_function_repr),
     func_code = getset_func_code, 
     func_doc = getset_func_doc,
-    func_name = interp_attrproperty('name', cls=Function), 
-    func_dict = getset_func_dict, 
+    func_name = getset_func_name,
+    func_dict = getset_func_dict,
     func_defaults = getset_func_defaults,
     func_globals = interp_attrproperty_w('w_func_globals', cls=Function),
     func_closure = GetSetProperty( Function.fget_func_closure ),
     __doc__ = getset_func_doc,
-    __name__ = interp_attrproperty('name', cls=Function),
+    __name__ = getset_func_name,
     __dict__ = getset_func_dict,
     __module__ = getset___module__,
     # XXX func_closure, etc.pp



More information about the Pypy-commit mailing list