New PEP: Attribute Access Handlers

Paul Prescod paul at prescod.net
Sun Jul 23 14:20:22 EDT 2000


Neel Krishnaswami wrote:
> 
> 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?

class x:
    def attr_x_foo( self, op, val ):
        if op=="get":
            self.__get_x()
        elif op=="set":
            self.__set_x(val)
        else:
            self.__del_x()

-- 
 Paul Prescod - Not encumbered by corporate consensus
New from Computer Associates: "Software that can 'think', sold by 
marketers who choose not to."




More information about the Python-list mailing list