[Python-bugs-list] [ python-Bugs-614555 ] Rewrite _reduce and _reconstructor in C
SourceForge.net
noreply@sourceforge.net
Wed, 12 Feb 2003 14:19:56 -0800
Bugs item #614555, was opened at 2002-09-25 14:15
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=614555&group_id=5470
Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
>Priority: 2
Submitted By: Guido van Rossum (gvanrossum)
Assigned to: Guido van Rossum (gvanrossum)
Summary: Rewrite _reduce and _reconstructor in C
Initial Comment:
The copy_reg defines two functions, _reduce() and
_reconstructor(), that are used for the pickling and
unpickling of new-style classes. These were originally
written in Python because the right implementation
wasn't entirely clear; _reduce() is actually called
from a C-level __reduce__ method defined in 'object',
and it references _reconstructor() in its return tuple.
It is now time to move both back into C for efficiency.
----------------------------------------------------------------------
>Comment By: Guido van Rossum (gvanrossum)
Date: 2003-02-12 17:19
Message:
Logged In: YES
user_id=6380
Lowering priority; when you use pickle protocol 2, none of
this Python code is used any more.
Jim's comment has been addressed by __newobj__ and
__getnewargs__ (see PEP 307).
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2002-11-14 11:46
Message:
Logged In: YES
user_id=6380
I'd like to add some comments from Jim Fulton on this (or a
related) issue so they don't get lost.
"""
I still need to think of a good way to handle this.
Currently, the pattern is a reduce return value of the form:
reconstructor, (some_class, object, None), some_state
but there is a more general case where an uninitialized
object can be gotten by calling "type.__new__(some_class)",
or even: "some_class.__new__(some_class)".
There are really two issues:
- It's too hard to write __reduce__ functions for this case, and
- Too much data needs to be stored in pickles.
A new pickling code would handler the later, but I also want
to solve the former problem.
One thought is to return: (copy_reg.new, (some_class, ),
some_state) where copy_reg.new is:
def new(class_): return class.__new__(class_)
The pickler could easily spot reduce returns with
copy_reg.new as the first value and generate a special
pickle code.
"""
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=614555&group_id=5470