Revised PEP 318 - Function/Method Decorator Syntax

Andrew Bennetts andrew-pythonlist at puzzling.org
Wed Jun 11 03:39:18 CEST 2003


On Tue, Jun 10, 2003 at 02:28:45PM -0000, Moshe Zadka wrote:
> On Tue, 10 Jun 2003, Andrew Bennetts <andrew-pythonlist at puzzling.org> wrote:
> 
> >     class EvilProperty(type):
> >         def __new__(cls, name, bases, d):
> >             return property(d.get('get'), d.get('set'), d.get('del'), d['__doc__'])

[Oops, I meant "d.get('__doc__')", not "d['__doc__']"...]

> >     
> >     class C(object):
> >         class x:
> >             """An evil test property"""
> >             __metaclass__ = EvilProperty
> >             def get(self):
> >                 print 'Getting'
> >                 return 1
> >             def set(self, value):
> >                 print 'Setting to', value
> 
> Wouldn't it be more readable (:)) if you did
> 
> class _EvilProperty(type):
>     ....
> class EvilProperty:
>     __metaclass__ = _EvilProperty
> 
> class C(object):
>     class x(EvilProperty):
>         def get(self):
[...etc...]

No, it wouldn't be more readable, because it wouldn't work...

-Andrew.






More information about the Python-list mailing list