diff options
author | Guido van Rossum <guido@python.org> | 2003-01-30 05:41:19 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2003-01-30 05:41:19 (GMT) |
commit | 4fba220f4ad9203894ef95512f8c9cc5593c5567 (patch) | |
tree | 51242f1842d2a2847759d8488af04a8d42671aab /Lib/pickle.py | |
parent | 45486176ea14884400188c604d5d3488f803ff2d (diff) | |
download | cpython-4fba220f4ad9203894ef95512f8c9cc5593c5567.zip cpython-4fba220f4ad9203894ef95512f8c9cc5593c5567.tar.gz cpython-4fba220f4ad9203894ef95512f8c9cc5593c5567.tar.bz2 |
Slight code rearrangement to avoid testing getstate twice.
Diffstat (limited to 'Lib/pickle.py')
-rw-r--r-- | Lib/pickle.py | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py index d62a5bd..9bd2394 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -417,29 +417,29 @@ class Pickler: getstate = getattr(obj, "__getstate__", None) - # A class may define both __getstate__ and __getnewargs__. - # If they are the same function, we ignore __getstate__. - # This is for the benefit of protocols 0 and 1, which don't - # use __getnewargs__. Note that the only way to make them - # the same function is something like this: - # - # class C(object): - # def __getstate__(self): - # return ... - # __getnewargs__ = __getstate__ - # - # No tricks are needed to ignore __setstate__; it simply - # won't be called when we don't generate BUILD. - # Also note that when __getnewargs__ and __getstate__ are - # the same function, we don't do the default thing of - # looking for __dict__ and slots either -- it is assumed - # that __getnewargs__ returns all the state there is - # (which should be a safe assumption since __getstate__ - # returns the *same* state). - if getstate and getstate == getnewargs: - return - if getstate: + # A class may define both __getstate__ and __getnewargs__. + # If they are the same function, we ignore __getstate__. + # This is for the benefit of protocols 0 and 1, which don't + # use __getnewargs__. Note that the only way to make them + # the same function is something like this: + # + # class C(object): + # def __getstate__(self): + # return ... + # __getnewargs__ = __getstate__ + # + # No tricks are needed to ignore __setstate__; it simply + # won't be called when we don't generate BUILD. + # Also note that when __getnewargs__ and __getstate__ are + # the same function, we don't do the default thing of + # looking for __dict__ and slots either -- it is assumed + # that __getnewargs__ returns all the state there is + # (which should be a safe assumption since __getstate__ + # returns the *same* state). + if getstate == getnewargs: + return + try: state = getstate() except TypeError, err: @@ -450,6 +450,7 @@ class Pickler: print repr(str(err)) raise # Not that specific exception getstate = None + if not getstate: state = getattr(obj, "__dict__", None) if not state: |