[Spambayes-checkins] spambayes/spambayes storage.py,1.5,1.6

Tim Peters tim_one at users.sourceforge.net
Sun May 25 23:34:15 EDT 2003


Update of /cvsroot/spambayes/spambayes/spambayes
In directory sc8-pr-cvs1:/tmp/cvs-serv22708/spambayes

Modified Files:
	storage.py 
Log Message:
PickledClassifier.load():  As an XXX commented suggested, use getstate/
setstate to copy the state.  The "new pickle" branch should probably also
change to call the base-class __init__(), but I don't have time to test
that now so left it alone.


Index: storage.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/spambayes/storage.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** storage.py	4 Mar 2003 05:42:22 -0000	1.5
--- storage.py	26 May 2003 05:34:13 -0000	1.6
***************
*** 85,89 ****
          # creates a temporary instance of PickledClassifier, from which
          # this object's state is copied.  This is a nuance of the way
!         # that pickle does its job
  
          if options.verbose:
--- 85,94 ----
          # creates a temporary instance of PickledClassifier, from which
          # this object's state is copied.  This is a nuance of the way
!         # that pickle does its job.
!         # Tim sez:  that's because this is an unusual way to use pickle.
!         # Note that nothing non-trivial is actually copied, though:
!         # assignment merely copies a pointer.  The actual wordinfo etc
!         # objects are shared between tempbayes and self, and the tiny
!         # tempbayes object is reclaimed when load() returns.
  
          if options.verbose:
***************
*** 99,108 ****
              fp.close()
  
-         # XXX: why not self.__setstate__(tempbayes.__getstate__())?
          if tempbayes:
!             self.wordinfo = tempbayes.wordinfo
!             self.nham = tempbayes.nham
!             self.nspam = tempbayes.nspam
! 
              if options.verbose:
                  print '%s is an existing pickle, with %d ham and %d spam' \
--- 104,113 ----
              fp.close()
  
          if tempbayes:
!             # Copy state from tempbayes.  The use of our base-class
!             # __setstate__ is forced, in case self is of a subclass of
!             # PickledClassifier that overrides __setstate__.
!             classifier.Classifier.__setstate__(self,
!                                                tempbayes.__getstate__())
              if options.verbose:
                  print '%s is an existing pickle, with %d ham and %d spam' \





More information about the Spambayes-checkins mailing list