Add posting-date. Add note about the copy module. Remove TBD -- this

PEP is complete AFAIAC.
This commit is contained in:
Guido van Rossum 2003-02-07 18:11:29 +00:00
parent a526eed9cb
commit 4d97872f0d
1 changed files with 43 additions and 3 deletions

View File

@ -7,7 +7,7 @@ Status: Active
Type: Standards Track
Content-Type: text/plain
Created: 31-Jan-2003
Post-History: None
Post-History: 7-Feb-2003
Introduction
@ -599,9 +599,49 @@ Extension registry API
It is up to applications to respect these.
TBD
The copy module
The rest of this PEP is still under construction!
Traditionally, the copy module has supported an extended subset of
the pickling APIs for customizing the copy() and deepcopy()
operations.
In particular, besides checking for a __copy__ or __deepcopy__
method, copy() and deepcopy() have always looked for __reduce__,
and for classic classes, have looked for __getinitargs__,
__getstate__ and __setstate__.
In Python 2.2, the default __reduce__ inherited from 'object' made
copying simple new-style classes possible, but slots and various
other special cases were not covered.
In Python 2.3, several changes are made to the copy module:
- The four- and five-argument return values of __reduce__ are
supported.
- Before looking for a __reduce__ method, the
copy_reg.dispatch_table is consulted, just like for pickling.
- When the __reduce__ method is inherited from object, it is
(unconditionally) replaced by a better one that uses the same
APIs as pickle protocol 2: __getnewargs__, __getstate__, and
__setstate__, handling list and dict subclasses, and handling
slots.
As a consequence of the latter change, certain new-style classes
that were copyable under Python 2.2 are not copyable under Python
2.3. (These classes are also not picklable using pickle protocol
2.) A minimal example of such a class:
class C(object):
def __new__(cls, a):
return object.__new__(cls)
The problem only occurs when __new__ is overridden and has at
least one mandatory argument in addition to the class argument.
To fix this, a __getnewargs__ method should be added that returns
the appropriate argument tuple (excluding the class).
Copyright