[Python-checkins] python/dist/src/Lib pickle.py,1.125,1.126

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Wed, 29 Jan 2003 21:41:22 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv26268

Modified Files:
	pickle.py 
Log Message:
Slight code rearrangement to avoid testing getstate twice.


Index: pickle.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pickle.py,v
retrieving revision 1.125
retrieving revision 1.126
diff -C2 -d -r1.125 -r1.126
*** pickle.py	30 Jan 2003 05:39:04 -0000	1.125
--- pickle.py	30 Jan 2003 05:41:19 -0000	1.126
***************
*** 418,444 ****
          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:
              try:
                  state = getstate()
--- 418,444 ----
          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
+             # 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()
***************
*** 451,454 ****
--- 451,455 ----
                      raise # Not that specific exception
                  getstate = None
+ 
          if not getstate:
              state = getattr(obj, "__dict__", None)