Revised PEP 318 - Function/Method Decorator Syntax
andrew-pythonlist at puzzling.org
Tue Jun 10 15:49:23 CEST 2003
On Tue, Jun 10, 2003 at 12:25:13PM +0000, Kevin Smith wrote:
> The proposed syntax is general enough that it could be used
> on class definitions as well as shown below.
> class foo(object) as classmodifier:
> class definition here
> However, there are no obvious parallels for use with other
> descriptors such as property().
Note that you can already do tricky stuff with properties if you really want
to define one all at once:
def __new__(cls, name, bases, d):
return property(d.get('get'), d.get('set'), d.get('del'), d['__doc__'])
"""An evil test property"""
__metaclass__ = EvilProperty
def set(self, value):
print 'Setting to', value
c = C()
c.x = 5
This has the advantage that you can define your property in a single block,
and you don't have to look too far ahead in the nested class to see the
crucial "__metaclass__ = EvilProperty" line.
It does kinda feel like yet-another-gratuitous-use-of-metaclasses, though ;)
More information about the Python-list