Title: copy.copy doesn't work on subclasses of newstyle classes
Type: Severity: normal
Components: Core Versions:
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: zyasoft Nosy List: cgroves, leouserz, pjenvey, zyasoft
Priority: normal Keywords:

Created on 2006-11-28.05:32:03 by cgroves, last changed 2008-11-23.04:46:23 by pjenvey.

msg1315 (view) Author: Charlie Groves (cgroves) Date: 2006-11-28.05:32:03
Trying to run copy.copy on subclasses of newstyle classes fails with this error: 

Error: un(shallow)copyable object of type <class '__main__.C'>

This causes copies in test_descr to fail.
msg1316 (view) Author: Deleted User leouserz (leouserz) Date: 2006-12-22.15:58:29
I see 2 problems so far. First it seems the defines TypeType as Class.fromClass(JavaClass.class), when it appears it should be

Second the .py src for copy seems not to match the from a 2.2 distribution Im looking at.  Changing it to the 2.2 alters the scenario allowing copies to be made.  But it seems that the dictionary from the instance is not being copied.  This causes a new error in test_descr copies to appear.  I will look further into this.

msg1317 (view) Author: Deleted User leouserz (leouserz) Date: 2006-12-22.17:26:19
it seems that the missing piece may be that PyObject is not returning its __dict__ if it has state.  The relevant method is object__reduce.  The pickling protocol clarifies what the different objects mean when returned by __reduce__:

From looking at cpython, if the Object has no state, None appears to be returned.  If it has state, the dictionary is returned.

msg3828 (view) Author: Philip Jenvey (pjenvey) Date: 2008-11-23.04:46:23
I can reproduce this on 2.2.1, but it's fixed on trunk -- maybe due to 
pickle v2 changes, or from all the pickle related fixes done to get 
test_*pickle passing. Closing out
Date User Action Args
2008-11-23 04:46:23pjenveysetstatus: open -> closed
nosy: + pjenvey
resolution: fixed
messages: + msg3828
2008-09-14 16:50:33zyasoftsetassignee: zyasoft
nosy: + zyasoft
2006-11-28 05:32:03cgrovescreate