[Python-ideas] Multiple arguments for decorators
Stephen J. Turnbull
stephen at xemacs.org
Mon Nov 30 22:16:30 EST 2015
David Mertz writes:
> On Mon, Nov 30, 2015 at 6:14 PM, Chris Angelico <rosuav at gmail.com> wrote:
>> def call(func):
>> def inner(cls):
>> return func(**{k:v for k,v in cls.__dict__.items() if not
>> k.startswith('_')})
>> return inner
>>
>> class Foo:
>> def __init__(self):
>> self._x = 42
>> @call(property)
>> class x:
>> def fget(self):
>> return self._x
>> def fset(self, value):
>> self._x = value
>> def fdel(self):
>> del self._x
>>
> I think this looks perfectly nice, actually.
That was my first thought too. The use of the "class" keyword was a
bit of a shock at first, but it grew on me, especially in this context
of @property (ie, if I think "@property defines a class with appropriate
behavior and installs instances on objects of the enclosing class").
I'm having trouble interpreting the function name "call", though. Am
I missing something obvious ("Angelico" doesn't sound Dutch to me,
though :-), or maybe there's a better (longer) name for it?
Also, can call be expected to DTRT for anything *but* property?
More information about the Python-ideas
mailing list