PEP 252: __slots__ inappropriate

Roman Suzi rnd at onego.ru
Thu Aug 16 05:38:41 EDT 2001


On Thu, 16 Aug 2001, Martin von Loewis wrote:

>In the current implementation of PEP 252, to declare an class with
>slots, you assign to the __slots__ variable inside the class
>definition:
>
>class Foo(object):
>  __slots__ = ['bar','baz']
>
>This declares that every instance of Foo will have two instance
>attributes, namely bar and baz.
>
>I find that this way of defining class properties is inconsistent with
>the rest of the language, in particular with other "magic" class
>attributes:

I agree with you. These keywords (__dunamic__, __slots__) are no more
than hidden memory class/type attributes, like register and struct
in C, that is, they are along with global NEW kinds of definitions.

I think, it needs to be dealt with or Python will end using lots of
definitions, added here and there without any consistency (for now, at
least - 'cause Guido concentrates on underlying mechanisms).

IF future of Python involves adding more declarations, it's time for
adding nice syntax to those and not hide them with __things__.


>  slot bar
>  slot baz = 42

It is consistent with global.

>This is similar in declaration to a global directive, except that that
>it would be a definition, not a declaration: It would create a member
>object.
>
>B. An existing keyword
>
>class Foo:
>  def bar
>  def baz = 42

no. This needs more words (cause slot is not the last declaration,
it seems):

def bar = 42, foo = 3 as __slots__

(or something like that)

>C. A new builtin
>
>class Foo:
>  bar = slot()
>  baz = slot(42)

No, this is not good, because slot is ooptimization hack involving
low-levels of Python implementation. (I am not at all happy it appears in
Python.)

>In this option, the slot object would not know what its name is. So
>this would require some magic, either at class definition time, or at
>slot access time.

Sincerely yours, Roman Suzi
-- 
_/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/
_/ Thursday, August 16, 2001 _/ Powered by Linux RedHat 6.2 _/
_/ ".ASM programmers drive stick shifts." _/





More information about the Python-list mailing list