Properties using metaclasses (was: Function/Method Decorator Syntax)

Gerrit Holl gerrit at nl.linux.org
Wed Jun 11 13:03:00 CEST 2003


Andrew Bennetts wrote:
> Subject: Re: Revised PEP 318 - Function/Method Decorator Syntax

> class _EvilProperty(type):
>     def __new__(cls, name, bases, d):
>         if d.get('__metaclass__') == _EvilProperty:
>             return type.__new__(cls, name, bases, d)
>         else:
>             return property(d.get('get'), d.get('set'), d.get('del'),
>                             d.get('__doc__'))
> 
> class EvilProperty:
>     __metaclass__ = _EvilProperty
> 
> class C(object):
>     class x(EvilProperty):
>         """An evil test property"""
>         def get(self):
>             print 'Getting'
>             return 1
>         def set(self, value):
>             print 'Setting to', value
>             
> c = C()
> print c.x
> c.x = 5  
> print C.x.__doc__

Just a question: Why would this be evil? I think it is explicit, simple,
sparse, readable, practical, unambiguous... The only real anti-zen-behaviour
is that it's nested rather than flat. But for the rest, I don't see the
problem, what is it?

yours,
Gerrit.

-- 
111. If an inn-keeper furnish sixty ka of usakani-drink to ... she
shall receive fifty ka of corn at the harvest.
        -- 1780 BC, Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
	http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
	http://www.sp.nl/





More information about the Python-list mailing list