[Zodb-checkins] CVS: Zope3/src/zodb/code - function.py:1.5

Jeremy Hylton jeremy@zope.com
Wed, 15 Jan 2003 14:54:43 -0500


Update of /cvs-repository/Zope3/src/zodb/code
In directory cvs.zope.org:/tmp/cvs-serv27905

Modified Files:
	function.py 
Log Message:
Make it illegal to create a persistent function with free variables.


=== Zope3/src/zodb/code/function.py 1.4 => 1.5 ===
--- Zope3/src/zodb/code/function.py:1.4	Tue Dec 31 13:06:23 2002
+++ Zope3/src/zodb/code/function.py	Wed Jan 15 14:54:11 2003
@@ -84,6 +84,13 @@
         self._v_side_effect = has_side_effect(func)
         self._pf_module = module
         self._pf_code = {}
+        # Python doesn't provide enough rope to recreate a closure.  The
+        # cell objects are opaque which means Python code can't extra
+        # the objects from them or recreate them on unpickling.  In
+        # principle this code be fixed with C code, but it should be
+        # done in Python, not Zope.
+        if func.func_code.co_freevars:
+            raise TypeError, "persistent function can not have free variables"
 
     def __repr__(self):
         return "<PersistentFunction %s.%s>" % (self._pf_module.__name__,