Is this a __slot__ bug?

Ian McMeans imcmeans at home.com
Sun Jun 30 22:58:21 EDT 2002


I wasn't able to find a good documentation of slots on the python website.
Do you have a link handy? I guess I'm just bad at searching, I couldn't find
a description in the first few pages of google either.

"Steve Menard" <steve.menard at vodeotron.ca> wrote in message
news:pan.2002.06.30.00.21.54.133520.5016 at vodeotron.ca...
> OK, this is probably me not understanding something, but then again, you
> never know.
>
> First things first, I love __slots__. For the paranoid programmer I am,
> knowing I will never again assing to a variable with a typo and then
> wonder ehat the hell is going wring is a godsend.
>
> However, I also love(need) private variables (those __X). It seems they
> dont work with slots. try the following simple example under ptyon 2.2 on
> linux :
>
> class O(object) :
> __slots__ = [
> '__a'
> ]
>
> def __init__(self) :
> object.__init__(self);
> self.__a = 3
> o = O()
>
> I get thoe following error :
> AttributeError: 'O' object has no attribute '_O__a'
>
> Now, I know I can easily work around this by manually obfuscating the
> private variables names in the __slots__, but I would rather not. Feels
> wrong somehow to rely on what should be a hidden way of generating
> private variables.
>
> So if this is by design, I will not agree but I will do the workaround.
> If not, well then seems I founda bug :)
>
> Steve





More information about the Python-list mailing list