[Python-Dev] Pre-PEP: Attribute Access Handlers v2

Vladimir Marangozov Vladimir.Marangozov@inrialpes.fr
Sat, 22 Jul 2000 19:56:03 +0200 (CEST)

> Paul Prescod wrote:
> > 
> > I don't have a PEP number for this yet but I wanted to go through
> > another round of comments after changing the mechanism according to Don
> > Beaudry's suggestions.
> > ...
> Paul, this is clearly unclear <0.1 wink>.

Thanks (Paul, Don, Gordon) for clarifying this pre-PEP.

As I see it, this aims at providing builtin support for the following
(simplified & quickly hacked) __getattr__ version:

def new_getattr(self, name, rec=0):

    hookname = "__get_%s__" % name
    if not rec and hasattr(self, hookname):
        hook =  new_getattr(self, hookname, rec=1)
        return hook(self)

    # builtin __getattr__ follows ...
    if self.__dict__.has_key(name):
        return self.__dict__[name]
    if self.__class__.__dict__.has_key(name):
        return self.__class__.__dict__[name]
    # ... return class_lookup(self, name)
    raise AttributeError, name

class C:
    def __get_hi__(self):
        return "coucou"
    def __getattr__(self, name):
        return new_getattr(self, name)

>>> c = C()
>>> c.hi

and its setattr, delattr counterparts. But people are already massively
using __getattr__ as method dispatchers, so as I understand it, this is
not just about "Attribute Access Handlers". You're looking for a
"Normative Naming Scheme and Builtin Support for Attribute Access Handlers",
no more, no less.

Okay, so make this clear in the PEP. The presented scenarios don't make
this clear, IMO. I asked myself what's the enhancement here...

Also, it would be useful if you could include a Python implementation of
the concept, stating explicitely where the existing functionality ends,
and where the proposed enhancement starts, so that people can play with it.

       Vladimir MARANGOZOV          | Vladimir.Marangozov@inrialpes.fr
http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252