Slight code rearrangement to avoid testing getstate twice.

This commit is contained in:
Guido van Rossum 2003-01-30 05:41:19 +00:00
parent 45486176ea
commit 4fba220f4a
1 changed files with 23 additions and 22 deletions

View File

@ -417,6 +417,7 @@ class Pickler:
getstate = getattr(obj, "__getstate__", None)
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
@ -436,10 +437,9 @@ class Pickler:
# 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:
if getstate == getnewargs:
return
if getstate:
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: