[Python-3000] Simplifying the copy protocol

Alexandre Vassalotti alexandre at peadrop.com
Mon Jun 9 00:26:17 CEST 2008


Hello all,

I would like to propose to following simplifications to the copy
protocol (a.k.a the __reduce__ method):

  - Remove the type.__reduce_ex__ method and define __reduce__ method
to take a single optional integer argument that is the pickle protocol
version to use. And since this already the current behavior of
__reduce__, no change is required.
  - Deprecate copyreg.pickle in favor of the __getnewargs__ special
method. They both solve the exact same problem, but __getnewargs__
does it in a simpler and more robust manner.
  - Make __reduce__ raise a TypeError if the class of an instance
derives from one or more extension type (object, list and dict
excluded) and neither __getnewargs__ nor __getstate__ is defined.

I believe that these changes will make it easier for developers to
write classes that supports the copy protocol, which is already quite
complex in addition of being poorly documented. Evidently, I will
provide the patches and write the documentation for these changes.

Cheers,
-- Alexandre


More information about the Python-3000 mailing list