Add __newobj__ and TBD section.
This commit is contained in:
parent
9cdeaa0b57
commit
ccc70922b4
35
pep-0307.txt
35
pep-0307.txt
|
@ -133,10 +133,11 @@ Extended __reduce__ API
|
|||
in this PEP. The items are, in order:
|
||||
|
||||
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.
|
||||
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.
|
||||
As a special case, designed for Zope 2's
|
||||
|
@ -184,6 +185,32 @@ Extended __reduce__ API
|
|||
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!
|
||||
|
||||
|
||||
Copyright
|
||||
|
||||
This document has been placed in the public domain.
|
||||
|
|
Loading…
Reference in New Issue