[Python-checkins] python/nondist/peps pep-0307.txt,1.4,1.5

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Sat, 01 Feb 2003 12:10:38 -0800


Update of /cvsroot/python/python/nondist/peps
In directory sc8-pr-cvs1:/tmp/cvs-serv5868

Modified Files:
	pep-0307.txt 
Log Message:
Add __newobj__ and TBD section.


Index: pep-0307.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep-0307.txt,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** pep-0307.txt	31 Jan 2003 21:58:34 -0000	1.4
--- pep-0307.txt	1 Feb 2003 20:10:35 -0000	1.5
***************
*** 134,141 ****
  
      function     A callable object (not necessarily a function) called
!                  to create the initial version of the object; state may
!                  be added to the object later to fully reconstruct the
!                  pickled state.  This function must itself be
!                  picklable.
  
      arguments    A tuple giving the argument list for the function.
--- 134,142 ----
  
      function     A callable object (not necessarily a function) called
!                  to create the initial version of the object; state
!                  may be added to the object later to fully reconstruct
!                  the pickled state.  This function must itself be
!                  picklable.  See the section about __newobj__ for a
!                  special case (new in this PEP) here.
  
      arguments    A tuple giving the argument list for the function.
***************
*** 183,186 ****
--- 184,213 ----
      2.3, __setstate__ will never be called when __reduce__ returns a
      state with value None.
+ 
+ 
+ The __newobj__ unpickling function
+ 
+     When the unpickling function returned by __reduce__ (the first
+     item of the returned tuple) has the name __newobj__, something
+     special happens for pickle protocol 2.  An unpickling function
+     named __newobj__ is assumed to have the following semantics:
+ 
+       def __newobj__(cls, *args):
+           return cls.__new__(cls, *args)
+ 
+     Pickle protocol 2 special-cases an unpickling function with this
+     name, and emits a pickling opcode that, given 'cls' and 'args',
+     will return cls.__new__(cls, *args) without also pickling a
+     reference to __newobj__.  This is the main reason why protocol 2
+     pickles are so much smaller than classic pickles.  Of course, the
+     pickling code cannot verify that a function named __newobj__
+     actually has the expected semantics.  If you use an unpickling
+     function named __newobj__ that returns something different, you
+     deserve what you get.
+ 
+ 
+ TBD
+ 
+     The rest of this PEP is still under construction!