Re: [Python-Dev] Fwd: Instance variable access and descriptors

2007-06-10 Thread Gustavo Carneiro

 I have to agree with you.  If removing support for
self.__dict__['propertyname'] (where propertyname is also the name of a
descriptor) is the price to pay for significant speedup, so be it.  People
doing that are asking for trouble anyway!

On 10/06/07, Eyal Lotem [EMAIL PROTECTED] wrote:


On 6/10/07, Phillip J. Eby [EMAIL PROTECTED] wrote:
 At 12:23 AM 6/10/2007 +0300, Eyal Lotem wrote:
 A. It will break code that uses instance.__dict__['var'] directly,
 when 'var' exists as a property with a __set__ in the class. I believe
 this is not significant.
 B. It will simplify getattr's semantics. Python should _always_ give
 precedence to instance attributes over class ones, rather than have
 very weird special-cases (such as a property with a __set__).

 Actually, these are features that are both used and desirable; I've
 been using them both since Python 2.2 (i.e., for many years
 now).  I'm -1 on removing these features from any version of Python,
even 3.0.

It is the same feature, actually, two sides of the same coin.
Why do you use self.__dict__['propertyname'] when you can use
self._propertyname?
Why even call the first form, which is both longer and causes
performance problems a feature?


 C. It will greatly speed up instance variable access, especially when
 the class has a large mro.

 ...at the cost of slowing down access to properties and __slots__, by
 adding an *extra* dictionary lookup there.
It will slow down access to properties - but that slowdown is
insignificant:
A. The vast majority of lookups are *NOT* of properties. They are the
rare case and should not be the focus of optimization.
B. Property access involves calling Python functions - which is
heavier than a single dict lookup.
C. The dict lookup to find the property in the __mro__ can involve
many dicts (so in those cases adding a single dict lookup is not
heavy).

 Note, by the way, that if you want to change attribute lookup
 semantics, you can always override __getattribute__ and make it work
 whatever way you like, without forcing everybody else to change *their*
code.
If I write my own __getattribute__ I lose the performance benefit that
I am after.
I do agree that code shouldn't be broken, that's why a transitional
that requires using __fastlookup__ can be used (Unfortunately, from
__future__ cannot be used as it is not local to a module, but to a
class hierarchy - unless one imports a feature from __future__ into a
class).
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/gjcarneiro%40gmail.com





--
Gustavo J. A. M. Carneiro
INESC Porto
The universe is always one step beyond logic. -- Frank Herbert
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Fwd: Instance variable access and descriptors

2007-06-10 Thread Phillip J. Eby
At 04:14 AM 6/10/2007 +0300, Eyal Lotem wrote:
On 6/10/07, Phillip J. Eby [EMAIL PROTECTED] wrote:
  At 12:23 AM 6/10/2007 +0300, Eyal Lotem wrote:
  A. It will break code that uses instance.__dict__['var'] directly,
  when 'var' exists as a property with a __set__ in the class. I believe
  this is not significant.
  B. It will simplify getattr's semantics. Python should _always_ give
  precedence to instance attributes over class ones, rather than have
  very weird special-cases (such as a property with a __set__).
 
  Actually, these are features that are both used and desirable; I've
  been using them both since Python 2.2 (i.e., for many years
  now).  I'm -1 on removing these features from any version of 
 Python, even 3.0.

It is the same feature, actually, two sides of the same coin.
Why do you use self.__dict__['propertyname'] when you can use
self._propertyname?

Because I'm *not writing this by hand*.  I'm using descriptors that 
know what attribute name they're responsible for, and do the access directly.


Why even call the first form, which is both longer and causes
performance problems a feature?

If you don't understand that, IMO you don't yet understand enough 
about the descriptor architecture to be proposing changes to it.


  Note, by the way, that if you want to change attribute lookup
  semantics, you can always override __getattribute__ and make it work
  whatever way you like, without forcing everybody else to change 
 *their* code.
If I write my own __getattribute__ I lose the performance benefit that
I am after.

Not if you write it in C.


I do agree that code shouldn't be broken, that's why a transitional
that requires using __fastlookup__ can be used (Unfortunately, from
__future__ cannot be used as it is not local to a module, but to a
class hierarchy - unless one imports a feature from __future__ into a
class).

I have no idea what you're talking about here.

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Fwd: Instance variable access and descriptors

2007-06-10 Thread Phillip J. Eby
At 11:27 AM 6/10/2007 +0100, Gustavo Carneiro wrote:
   I have to agree with you.  If removing support for 
 self.__dict__['propertyname'] (where propertyname is also the name 
 of a descriptor) is the price to pay for significant speedup, so be 
 it.  People doing that are asking for trouble anyway!

How so?  This order of lookup is explicitly defined by the precedence 
rules of PEP 252:

When a dynamic attribute (one defined in a regular object's
__dict__) has the same name as a static attribute (one defined
by a meta-object in the inheritance graph rooted at the regular
object's __class__), the static attribute has precedence if it
is a descriptor that defines a __set__ method (see below);
otherwise (if there is no __set__ method) the dynamic attribute
has precedence.  In other words, for data attributes (those
with a __set__ method), the static definition overrides the
dynamic definition, but for other attributes, dynamic overrides
static.

I fail to see how relying on explicitly-documented language behavior 
is asking for trouble. 

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] Fwd: Instance variable access and descriptors

2007-06-09 Thread Eyal Lotem
On 6/10/07, Phillip J. Eby [EMAIL PROTECTED] wrote:
 At 12:23 AM 6/10/2007 +0300, Eyal Lotem wrote:
 A. It will break code that uses instance.__dict__['var'] directly,
 when 'var' exists as a property with a __set__ in the class. I believe
 this is not significant.
 B. It will simplify getattr's semantics. Python should _always_ give
 precedence to instance attributes over class ones, rather than have
 very weird special-cases (such as a property with a __set__).

 Actually, these are features that are both used and desirable; I've
 been using them both since Python 2.2 (i.e., for many years
 now).  I'm -1 on removing these features from any version of Python, even 3.0.

It is the same feature, actually, two sides of the same coin.
Why do you use self.__dict__['propertyname'] when you can use
self._propertyname?
Why even call the first form, which is both longer and causes
performance problems a feature?


 C. It will greatly speed up instance variable access, especially when
 the class has a large mro.

 ...at the cost of slowing down access to properties and __slots__, by
 adding an *extra* dictionary lookup there.
It will slow down access to properties - but that slowdown is insignificant:
A. The vast majority of lookups are *NOT* of properties. They are the
rare case and should not be the focus of optimization.
B. Property access involves calling Python functions - which is
heavier than a single dict lookup.
C. The dict lookup to find the property in the __mro__ can involve
many dicts (so in those cases adding a single dict lookup is not
heavy).

 Note, by the way, that if you want to change attribute lookup
 semantics, you can always override __getattribute__ and make it work
 whatever way you like, without forcing everybody else to change *their* code.
If I write my own __getattribute__ I lose the performance benefit that
I am after.
I do agree that code shouldn't be broken, that's why a transitional
that requires using __fastlookup__ can be used (Unfortunately, from
__future__ cannot be used as it is not local to a module, but to a
class hierarchy - unless one imports a feature from __future__ into a
class).
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com