PEP idea. ( removing __slots__ )

S

simon place

Removing __slots__
~~~~~~~~~~~~~~~~~~~

To do this nicely requires the renaming of __dict__ to, say,
__attribs__ , ( since dict is unnecessarily unspecific, this seem like a
small improvement in itself. ) then using the setting of __attribs__ to
a non-mutable type (ie tuple of attribute names) to indicate the
behaviour of __slots__, rendering it unnecessary, this I think is a good
simplification.
 
S

simon place

The point is to combine __dict__ and __slots__ into a new __attribs__,
the distinction being the type of __attribs__. If you don't specify
__attribs__ in the class you get the default __dict__ behavior, if you
do, and use a tuple, then you get the __slots__ behavior, and you can
easily tell which by checking the type, you could also iterate over the
attributes without caring which it was.
 
M

Martin v. =?iso-8859-15?q?L=F6wis?=

simon place said:
The point is to combine __dict__ and __slots__ into a new __attribs__,
the distinction being the type of __attribs__. If you don't specify
__attribs__ in the class you get the default __dict__ behavior, if you
do, and use a tuple, then you get the __slots__ behavior, and you can
easily tell which by checking the type, you could also iterate over
the attributes without caring which it was.

So how is this different from the current situation? If you don't
specify __slots__, you get the default __dict__ behaviour, if you do,
and use a tuple, you get the __slots__ behaviour, and you can easily
tell which by checking the type.

You also have the case of both __slots__ and __dict__ being in a type,
and this is a useful case also.

Regards,
Martin
 
S

simon place

i can't think of a point for __slots__ except to save the overhead of a
dict, this is why you DON'T HAVE a __dict__ when __slots__ is defined.

__slots__ should generally be used to improve the performance/footprint
of small/transient classes, ( it also prevents new instance variables
but this appears to be more of a side effect.)

The point of the combining is to simplify, you know, based on the idea
that keeping the language simply ( and logical ) aids comprehension.
 
M

Martin v. =?iso-8859-15?q?L=F6wis?=

simon place said:
i can't think of a point for __slots__ except to save the overhead of
a dict, this is why you DON'T HAVE a __dict__ when __slots__ is
defined.

No. Some classes have slots for efficiency, and their subclasses have
dictionaries for generality.

Likewise, some classes have slots to save the dictionary for most
instances, but some instances may need additional attributes, in which
case Python creates the dictionary on-the-fly.
The point of the combining is to simplify, you know, based on the idea
that keeping the language simply ( and logical ) aids comprehension.

I know.

Regards,
Martin
 
S

simon place

No. Some classes have slots for efficiency, and their subclasses have
dictionaries for generality.

Likewise, some classes have slots to save the dictionary for most
instances, but some instances may need additional attributes, in which
case Python creates the dictionary on-the-fly.

I know subclasses can add a __dict__, but i really thought a class with
__slots__ could not have a __dict__, doesn't the script below show this
behavior?


PythonWin 2.3b2 (#43, Jun 29 2003, 16:43:04) [MSC v.1200 32 bit (Intel)]
on win32.
Portions Copyright 1994-2001 Mark Hammond ([email protected]) -
see 'Help/About PythonWin' for further copyright information..... __slots__=['a']
.... Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
 
U

Ulrich Petri

simon place said:
I know subclasses can add a __dict__, but i really thought a class with
__slots__ could not have a __dict__, doesn't the script below show this
behavior?
<snip>

Consider this:


C:\Dokumente und Einstellungen\Administrator>python
Python 2.3a2 (#39, Feb 19 2003, 17:58:58) [MSC v.1200 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information..... __slots__ = ['a','__dict__']
....
which of course is kina wierd....

Ciao Ulrich
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top