[Python-Dev] Re: new syntax for wrapping (PEP 318)

Alan Green alan.green at cardboard.nu
Fri Feb 27 06:25:30 EST 2004


Barry Warsaw <barry <at> python.org> writes: 
 
> Just what /is/ the contract for a decorator function?  Maybe that it 
> takes a function/method object and must return a descriptor?  I do think 
> this needs some clarification in the PEP. 
 
It would be really spiffy if the decorator were able to run the decorated 
function and then have access to the function's locals dictionary. It would 
then be possible to define a property like so: 
 
class Foo(object): 
    def bar(self) [property]: 
        """ bar property docstring """ 
        def get(self):  
            return self.__bar 
        def set(self, bar): 
            self.__bar = bar 
 
The property decorator would reach inside the locals dictionary amd pull out  
the special names 'get', 'set' and 'delete', and use them to construct the 
property descriptor. 
 
-- 
Alan.  
-- 
 
 
 




More information about the Python-Dev mailing list