New PEP: Attribute Access Handlers

Neel Krishnaswami neelk at brick.cswv.com
Sun Jul 23 10:33:42 EDT 2000


Gordon McMillan <gmcm at hypernet.com> wrote:
> 
> Of course you don't! Because Paul forgot to tell you that the first
> proposal said that defining one or more of __set/get/del_XXX__
> automatically defines all 3, with default behavior of "you can't do
> that". So a base class defining __get_X__ and a derived class
> defining __set_X__ will have the wrong semantics 50% of the time
> whichever way you choose to handle it.

I'm afraid I still don't understand. If I wanted to use separate
accessors/mutators, what would I do with the current proposal?

An example (using separate accessors) that I'd like to see translated:

class Foo:
   def __init__(self, x):
       self.x = x


class LogWrites(Foo):
   def __set_x__(self, x, val):
       add_to_write_log()
       self.__dict__['x'] = val


class LogReads(Foo):
   def __get_x__(self, x):
       add_to_read_log()
       return self.__dict__['x']

Thanks.


Neel



More information about the Python-list mailing list