Classes can use the same interfaces to control copying that they use
to control pickling: they can define methods called __getinitargs__(),
-__getstate__() and __setstate__(). See the __doc__ string of module
+__getstate__() and __setstate__(). See the documentation for module
"pickle" for information on these methods.
"""
return x.__copy__()
if hasattr(x, '__getinitargs__'):
args = x.__getinitargs__()
+ y = apply(x.__class__, args)
else:
- args = ()
- y = apply(x.__class__, args)
+ y = _EmptyClass()
+ y.__class__ = x.__class__
if hasattr(x, '__getstate__'):
state = x.__getstate__()
else:
args = x.__getinitargs__()
_keep_alive(args, memo)
args = deepcopy(args, memo)
+ y = apply(x.__class__, args)
else:
- args = ()
- y = apply(x.__class__, args)
+ y = _EmptyClass()
+ y.__class__ = x.__class__
memo[id(x)] = y
if hasattr(x, '__getstate__'):
state = x.__getstate__()
del types
+# Helper for instance creation without calling __init__
+class _EmptyClass:
+ pass
+
def _test():
l = [None, 1, 2L, 3.14, 'xyzzy', (1, 2L), [3.14, 'abc'],
{'abc': 'ABC'}, (), [], {}]