Issue651701
This issue tracker has been migrated to GitHub,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2002-12-10 23:10 by pafein, last changed 2022-04-10 16:05 by admin. This issue is now closed.
Files | ||||
---|---|---|---|---|
File name | Uploaded | Description | Edit | |
bozo_getstate.py | pafein, 2002-12-10 23:13 | bug demo |
Messages (7) | |||
---|---|---|---|
msg13587 - (view) | Author: Peter Fein (pafein) | Date: 2002-12-10 23:10 | |
The bozo __getstate__ set automatically on classes defining __slots__ overrides any __getstate__ defined in a base class. This makes writing a mixin to implement this method impossible. |
|||
msg13588 - (view) | Author: Neal Norwitz (nnorwitz) * | Date: 2003-05-22 21:58 | |
Logged In: YES user_id=33168 What do you expect to be printed? I'm not sure what you want changed. Have you tested with 2.3b1? Does this meet your needs? |
|||
msg13589 - (view) | Author: Peter Fein (pafein) | Date: 2003-05-22 22:09 | |
Logged In: YES user_id=639329 This issue is that although the base class B defines a __getstate__, the class C2 overrides it b/c it contains __slots__. Basically, I'm suggesting that base classes should be checked for getstate instead of only looking at the class that defines slots before adding the bozo'd version. Unfortunately, I don't have a 2.3* version to play with at the moment. Please let me know if this clarifies things. |
|||
msg13590 - (view) | Author: Neal Norwitz (nnorwitz) * | Date: 2003-05-22 22:15 | |
Logged In: YES user_id=33168 There was an issue with that, IIRC. There was a discussion on python-dev a while ago which Guido talked about the issues. I don't remember when or what the issues were. Probably about 3-6 months ago. I think the code in this area may have changed, so it would be beneficial to test with 2.3b1. |
|||
msg13591 - (view) | Author: Raymond Hettinger (rhettinger) * | Date: 2003-07-12 01:36 | |
Logged In: YES user_id=80475 Peter, is this still an issue? Can you attach a script demonstrating the problem? |
|||
msg13592 - (view) | Author: Andrew Straw (astraw) | Date: 2003-11-24 05:28 | |
Logged In: YES user_id=210276 I'm experiencing this behavior on Python 2.2.2 and 2.2.3. I don't get it on 2.2(.0) or 2.3(.x). Here's a script that demonstrates: (Sorry SF doesn't seem to have a nice attachment feature for comments.) import sys print 'Python version',sys.version print def recursive_base_class_finder(klass): """A function to find all base classes.""" result = [klass] for base_class in klass.__bases__: for base_base_class in recursive_base_class_finder(base_class): result.append(base_base_class) # Make only a single copy of each class found result2 = [] for r in result: if r not in result2: result2.append(r) return result2 class A(object): __slots__ = ['a'] def __getstate__(self): """support for being pickled""" result = {} classes = recursive_base_class_finder(self.__class__) for klass in classes: if hasattr(klass,'__slots__'): for attr in klass.__slots__: if hasattr(self,attr): result[attr] = getattr(self,attr) return result def __setstate__(self,dict): for attr in dict.keys(): setattr(self,attr,dict[attr]) def __init__(self): self.a='a' class B(A): __slots__ = ['b'] def __init__(self): A.__init__(self) self.b = 'b' a1=A() b1=B() import pickle ap = pickle.dumps(a1) bp = pickle.dumps(b1) a2 = pickle.loads(ap) b2 = pickle.loads(bp) if a2.a == 'a': print 'pickling/unpickling ok' else: print 'WARNING: pickling/unpickling failed' if b2.a == 'a' and b2.b == 'b': print 'pickling/unpickling on derived class ok' else: print 'WARNING: pickling/unpickling on dericed class failed' try: a2.xx = 'x' failed = 0 except: failed = 1 if not failed: print "WARNING: assigned to attribute not in __slots__" try: b2.xx = 'x' failed = 0 except: failed = 1 if not failed: print "WARNING: assigned to attribute in derived class not in __slots__" |
|||
msg13593 - (view) | Author: Georg Brandl (georg.brandl) * | Date: 2005-10-01 13:04 | |
Logged In: YES user_id=1188172 Not present on 2.3.5, 2.4.2 and 2.5cvs. Closing as Fixed. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-10 16:05:59 | admin | set | github: 37600 |
2002-12-10 23:10:36 | pafein | create |