Erm... might I suggest... (Re: New PEP: Attribute Access Handlers)

Ben Wolfson rumjuggler at cryptarchy.org
Tue Jul 25 01:36:05 EDT 2000


On Tue, 25 Jul 2000 00:12:15 -0500, Paul Prescod <paul at prescod.net> wrote:

>Greg Ewing wrote:
>> 
>> To get attribute attr_name:
>>    if attr_name is in the instance dict:
>>       return it
>
>If I understand this correctly, then the very first time you add the
>attribute to the dict you effectively wipe out the accessor because the
>test above will evaluate true every time and the branch that uses
>accessors will never get called.
>
>If so, then your proposal does not allow the use of the XXX entry in the
>dict for arbitrary values. That would have been the primary benefit over
>my latest proposal.

What about:

To get attribute attr_name:
   if attr_name is in the instance dict:
      if the class's has_get_accessors flag is not set:
         return it
      else:
         translate attr_name to interned get_accessor_name using cache
         for each class along the inheritance path:
            if the class's has_get_accessors flag is set and it contains
               a method called get_accessor_name:
                  call it and return the result
            else:
               if the class contains an attribute called attr_name:
                  return it
   for each class along the inheritance path:
      if the class has a __getattr__ method:
         call it and return the result
   raise AttributeError

That way, if I understand correctly, a class can still (actually, must) use
the same XXX for __dict__['XXX'] and __get_XXX__.

-- 
Barnabas T. Rumjuggler

My words but a whisper, your deafness a SHOUT.
 -- Jethro Tull, "Thick as a Brick"



More information about the Python-list mailing list