[Patches] [ python-Patches-565085 ] copy._reduction doesn't __setstate__

noreply@sourceforge.net noreply@sourceforge.net
Thu, 06 Jun 2002 10:42:23 -0700


Patches item #565085, was opened at 2002-06-05 19:20
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=565085&group_id=5470

Category: Library (Lib)
Group: Python 2.3
>Status: Closed
>Resolution: Accepted
Priority: 5
Submitted By: Jay T Miller (jaytmiller)
Assigned to: Guido van Rossum (gvanrossum)
Summary: copy._reduction doesn't  __setstate__

Initial Comment:
The _reduction function in copy doesn't call
__setstate__, but instead always updates the dictionary
of an object directly.   This results in incorrect
copies for objects which define __setstate__.  This
seems like it may apply to all python versions.

Index: copy.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/copy.py,v
retrieving revision 1.26
diff -c -r1.26 copy.py
*** copy.py	2 Jun 2002 18:55:56 -0000	1.26
--- copy.py	5 Jun 2002 23:13:31 -0000
***************
*** 301,307 ****
      if state:
          if deep:
              state = deepcopy(state, memo)
!         y.__dict__.update(state)
      return y
  
  del d
--- 301,310 ----
      if state:
          if deep:
              state = deepcopy(state, memo)
!         if hasattr(y, '__setstate__'):
!             y.__setstate__(state)
!         else:
!             y.__dict__.update(state)
      return y
  
  del d


----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2002-06-06 13:42

Message:
Logged In: YES 
user_id=6380

Thanks!  Applied to trunk, will apply to 2.2 branch too.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=565085&group_id=5470