[Python-Dev] Pickle implementation questions

"Martin v. Löwis" martin at v.loewis.de
Fri Jun 30 07:09:19 CEST 2006

Bruce Christensen wrote:
> In developing a cPickle module for IronPython that's as compatible as
> possible with CPython, these questions have come up: 

[I wish you were allowed to read the source code of Python]

>  - Where are object.__reduce__ and object.__reduce_ex__ defined, and how
> does copy_reg._reduce_ex fit into the picture? 



> PEP 307 states that the
> default __reduce__ implementation for new-style classes implemented in
> Python is copy_reg._reduce. However, in  Python 2.4.3 dir(copy_reg)
> indicates that it has no _reduce method.

Yes, it calls copy_reg._reduce_ex now (which also expects the protocol

>  - When the optional constructor argument is passed to copy_reg.pickle,
> where is it stored and how is it used by pickle?

It's not used anymore. A comment says

    # The constructor_ob function is a vestige of safe for unpickling.
    # There is no reason for the caller to pass it anymore.

>  - What does copy_reg.constructor() do?

It does this:

def constructor(object):
    if not callable(object):
        raise TypeError("constructors must be callable")


More information about the Python-Dev mailing list