]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Use __dict__.update(state) instead of for loop over state.items() and
authorGuido van Rossum <guido@python.org>
Sun, 26 Oct 1997 17:00:25 +0000 (17:00 +0000)
committerGuido van Rossum <guido@python.org>
Sun, 26 Oct 1997 17:00:25 +0000 (17:00 +0000)
call to setattr().  This changes semantics, following the change
already implemented in pickle.

Also reindented a few lines properly.

Lib/copy.py

index ef1598285b311dd22ed00fb1ae4bdbb31ff2006f..51c375d65fcf53959547077c93e0ac8577e0d30a 100644 (file)
@@ -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