Kaydet (Commit) e6eef4b4 authored tarafından Guido van Rossum's avatar Guido van Rossum

Use __dict__.update(state) instead of for loop over state.items() and

call to setattr().  This changes semantics, following the change
already implemented in pickle.

Also reindented a few lines properly.
üst 040e5652
...@@ -111,14 +111,13 @@ def _copy_inst(x): ...@@ -111,14 +111,13 @@ def _copy_inst(x):
args = () args = ()
y = apply(x.__class__, args) y = apply(x.__class__, args)
if hasattr(x, '__getstate__'): if hasattr(x, '__getstate__'):
state = x.__getstate__() state = x.__getstate__()
else: else:
state = x.__dict__ state = x.__dict__
if hasattr(y, '__setstate__'): if hasattr(y, '__setstate__'):
y.__setstate__(state) y.__setstate__(state)
else: else:
for key in state.keys(): y.__dict__.update(state)
setattr(y, key, state[key])
return y return y
d[types.InstanceType] = _copy_inst d[types.InstanceType] = _copy_inst
...@@ -225,16 +224,15 @@ def _deepcopy_inst(x, memo): ...@@ -225,16 +224,15 @@ def _deepcopy_inst(x, memo):
y = apply(x.__class__, args) y = apply(x.__class__, args)
memo[id(x)] = y memo[id(x)] = y
if hasattr(x, '__getstate__'): if hasattr(x, '__getstate__'):
state = x.__getstate__() state = x.__getstate__()
_keep_alive(state, memo) _keep_alive(state, memo)
else: else:
state = x.__dict__ state = x.__dict__
state = deepcopy(state, memo) state = deepcopy(state, memo)
if hasattr(y, '__setstate__'): if hasattr(y, '__setstate__'):
y.__setstate__(state) y.__setstate__(state)
else: else:
for key in state.keys(): y.__dict__.update(state)
setattr(y, key, state[key])
return y return y
d[types.InstanceType] = _deepcopy_inst d[types.InstanceType] = _deepcopy_inst
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment