[Python-Dev] getstate() not inherited when slots present (original) (raw)
Greg Ward gward@python.net
Sun, 8 Dec 2002 18:09:41 -0500
- Previous message: [Python-Dev] zipimport, round 3 (or would that be that 37?)
- Next message: [Python-Dev] __getstate__() not inherited when __slots__ present
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
If a class and its superclass both define slots, it appears that getstate() is not inherited from the superclass. Example:
""" class Base (object): slots = []
def __getstate__ (self):
return tuple([getattr(self, attr) for attr in self.__slots__])
class Thing (Base): slots = ['a', 'b']
def __init__ (self):
self.a = 42
self.b = "boo!"
abstract = Base() thing = Thing()
print abstract.getstate print thing.getstate """
When I run this with a not-quite-current CVS Python:
<bound method Base.__getstate__ of <__main__.Base object at 0x401f73b8>>
The upshot of this is that I can't just define one getstate() in the superclass of a bunch of slots-using classes -- I guess I'll have to set getstate manually for each class. ;-( If this is a feature, is it documented anywhere?
(BTW, I see the same behaviour with Python 2.2.2.)
Greg
-- Greg Ward <gward@python.net> http://www.gerg.ca/ "Very funny, Scotty. Now beam my clothes down."
- Previous message: [Python-Dev] zipimport, round 3 (or would that be that 37?)
- Next message: [Python-Dev] __getstate__() not inherited when __slots__ present
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]