__slots__ questions (v2.2.2)
phoebe_1 at att.net.remove_me
Tue Oct 15 18:51:11 CEST 2002
It looks the the __slots__ bug that people have reported earlier, where a
'slotted' variable starting with '__' (double
underscore is name mangled is still not fixed in v2.2.2. Are there any plans
to fix this?
__slots__ = [ '__x']
self.__x = None
The above craps out with the Attribute error '_X__x' not found.
Also, in python 2.2.2 as in 2.2.1, a variable in the '__slots__' *must*
still be initialized 'before use'. I do not whether
it is supposed to work that way. If it is, then it seem very
counter-intuitive (well, if you are in the new features bandwagon). To
__slots__ = ['_x']
xobj = X()
the above gives attribute error. (in v2.2.1 and v2.2.2). I was expecting
that if you use '__slots__', all the 'slotted'
variables would get 'instantiated' when an instance is created and default
to None. But now, I have to explicitly
initialize by providing a __init__ method and setting '_x' to something.
To put it another way, I cannot 'get' a slotted variable *unless* it has
been "set" first .
Currently, I am using the 'metaclass' technique to alleviate the above
problem. But I would rather have python support
More information about the Python-list