mirror of
https://github.com/python/cpython.git
synced 2025-11-26 21:33:10 +00:00
_reconstructor(): there's no need for tricks with assignment to
__class__. The __new__ protocol is up to this. (Thanks to Tim for pointing this out.)
This commit is contained in:
parent
d48004f4f0
commit
698acf98fd
1 changed files with 2 additions and 9 deletions
|
|
@ -36,16 +36,9 @@ pickle(type(1j), pickle_complex, complex)
|
||||||
|
|
||||||
# Support for picking new-style objects
|
# Support for picking new-style objects
|
||||||
|
|
||||||
_dummy_classes = {}
|
|
||||||
|
|
||||||
def _reconstructor(cls, base, state):
|
def _reconstructor(cls, base, state):
|
||||||
dummy = _dummy_classes.get(base)
|
obj = base.__new__(cls, state)
|
||||||
if dummy is None:
|
base.__init__(obj, state)
|
||||||
class dummy(base): pass
|
|
||||||
_dummy_classes[base] = dummy
|
|
||||||
obj = dummy(state)
|
|
||||||
obj._foo = 1; del obj._foo # hack to create __dict__
|
|
||||||
obj.__class__ = cls
|
|
||||||
return obj
|
return obj
|
||||||
_reconstructor.__safe_for_unpickling__ = 1
|
_reconstructor.__safe_for_unpickling__ = 1
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue