[Python-Dev] Instance variable access and descriptors

Armin Rigo arigo at tunes.org
Mon Jun 11 13:06:13 CEST 2007

Hi Eyal,

On Sun, Jun 10, 2007 at 04:13:38AM +0300, Eyal Lotem wrote:
> I must be missing something, as I really see no reason to keep the
> existing semantics other than backwards compatibility (which can be
> achieved by introducing a __fastattr__ or such).
> Can you explain under which situations or find any example situation
> where the existing semantics are desirable?

The existing semantics are essential when dealing with metaclasses.
Many of the descriptors of the 'type' class would stop working without
it.  For example, the fact that 'x.__class__' normally gives the type of
'x' for any object x relies on this.  Reading the '__dict__' attribute
of types is also based on this.  Before proposing changes, be sure you
understand exactly how the following works:

    >>> object.__class__
    <type 'type'>
    >>> object.__dict__['__class__']
    <attribute '__class__' of 'object' objects>

    >>> class A(object):
    ...     pass
    >>> A.__dict__
    <dictproxy object at 0xb7c98e6c>
    >>> A.__dict__['__dict__']
    <attribute '__dict__' of 'A' objects>

A bientot,


More information about the Python-Dev mailing list