Is this a __slot__ bug?

Steve Menard steve.menard at vodeotron.ca
Sat Jun 29 20:21:54 EDT 2002


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