[Python-checkins] python/dist/src/Lib copy_reg.py,1.18,1.19

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Mon, 10 Feb 2003 13:32:01 -0800


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

Modified Files:
	copy_reg.py 
Log Message:
Get rid of the "bozo" __getstate__ that was inserted when __slots__
was used.  This simplifies some logic in copy_reg.py (used by
pickling).  It also broke a test, but this was rewritten to test the
new feature. :-)


Index: copy_reg.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/copy_reg.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** copy_reg.py	7 Feb 2003 20:56:38 -0000	1.18
--- copy_reg.py	10 Feb 2003 21:31:25 -0000	1.19
***************
*** 59,62 ****
--- 59,65 ----
          getstate = self.__getstate__
      except AttributeError:
+         if getattr(self, "__slots__", None):
+             raise TypeError("a class that defines __slots__ without "
+                             "defining __getstate__ cannot be pickled")
          try:
              dict = self.__dict__
***************
*** 84,97 ****
      getstate = getattr(obj, "__getstate__", None)
      if getstate:
!         try:
!             state = getstate()
!         except TypeError, err:
!             # XXX Catch generic exception caused by __slots__
!             if str(err) != ("a class that defines __slots__ "
!                             "without defining __getstate__ "
!                             "cannot be pickled"):
!                 raise # Not that specific exception
!             getstate = None
!     if not getstate:
          state = getattr(obj, "__dict__", None)
          names = _slotnames(cls)
--- 87,92 ----
      getstate = getattr(obj, "__getstate__", None)
      if getstate:
!         state = getstate()
!     else:
          state = getattr(obj, "__dict__", None)
          names = _slotnames(cls)