[Python-Dev] __slots__ (Change in evaluation order in new object model)

M.-A. Lemburg mal@lemburg.com
Thu, 08 Nov 2001 09:59:17 +0100


Tim Peters wrote:
> 
> [Michael McLay]
> > ...
> > The lookup of a member is also faster because it uses a lookup of
> > an offset instead of a dictionary lookup.
> 
> There's still a dict lookup:  when you do obj.a where a is a __slot__
> attribute of obj.__class__, obj.__class__.__dict__['a'] is looked up in
> order to get the descriptor for attribute 'a'.  The fixed set of __slot__
> attributes leaves a door open for future optimizations, though (e.g., if
> Python could *know* obj.__class__ at compile-time, and know that runtime
> code won't overwrite the 'a' descriptor in obj.__class__.__dict__, it could
> map obj.a directly to its storage offset (from the base of obj) at
> compile-time).

That'd be cool :-)

Say, would it also be possible to use __slots__ for methods ?
Or even make all methods defined in the class automagically
become __slots__ members ? (As I understood your explanations,
__slots__ would not interfere with class attributes, only instance
attributes, so this should be possible, right ?)

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Consulting & Company:                           http://www.egenix.com/
Python Software:                        http://www.lemburg.com/python/