summaryrefslogtreecommitdiffstats
path: root/Lib/copy.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-10-26 17:00:25 (GMT)
committerGuido van Rossum <guido@python.org>1997-10-26 17:00:25 (GMT)
commite6eef4b4a3a11b00fe5eae44e1af667de0b138b9 (patch)
tree63ddac63585f26a5a4f7af9991adfbe4d6e21e9a /Lib/copy.py
parent040e5652612a96b0046a25ba3f60dc0f8d0aad4d (diff)
downloadcpython-e6eef4b4a3a11b00fe5eae44e1af667de0b138b9.zip
cpython-e6eef4b4a3a11b00fe5eae44e1af667de0b138b9.tar.gz
cpython-e6eef4b4a3a11b00fe5eae44e1af667de0b138b9.tar.bz2
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.
Diffstat (limited to 'Lib/copy.py')
-rw-r--r--Lib/copy.py20
1 files changed, 9 insertions, 11 deletions
diff --git a/Lib/copy.py b/Lib/copy.py
index ef15982..51c375d 100644
--- a/Lib/copy.py
+++ b/Lib/copy.py
@@ -111,14 +111,13 @@ def _copy_inst(x):
args = ()
y = apply(x.__class__, args)
if hasattr(x, '__getstate__'):
- state = x.__getstate__()
+ state = x.__getstate__()
else:
- state = x.__dict__
+ state = x.__dict__
if hasattr(y, '__setstate__'):
- y.__setstate__(state)
+ y.__setstate__(state)
else:
- for key in state.keys():
- setattr(y, key, state[key])
+ y.__dict__.update(state)
return y
d[types.InstanceType] = _copy_inst
@@ -225,16 +224,15 @@ def _deepcopy_inst(x, memo):
y = apply(x.__class__, args)
memo[id(x)] = y
if hasattr(x, '__getstate__'):
- state = x.__getstate__()
- _keep_alive(state, memo)
+ state = x.__getstate__()
+ _keep_alive(state, memo)
else:
- state = x.__dict__
+ state = x.__dict__
state = deepcopy(state, memo)
if hasattr(y, '__setstate__'):
- y.__setstate__(state)
+ y.__setstate__(state)
else:
- for key in state.keys():
- setattr(y, key, state[key])
+ y.__dict__.update(state)
return y
d[types.InstanceType] = _deepcopy_inst