confusion with decorators

Steven D'Aprano steve+comp.lang.python at
Thu Jan 31 22:31:13 CET 2013

Steven D'Aprano wrote:

>> def _protector_decorator(fcn):
>>     def newfcn(self, *args, **kwargs):
>>         return fcn(self, *args, **kwargs)
>>     return newfcn
> Well, that surely isn't going to work, because it always decorates the
> same function, the global "fcn".

Good grief, I can't believe I failed to see that fcn was declared as a 
parameter to _protector_decorator.

> You probably want to add an extra parameter to the newfcn definition:
> def newfcn(self, fcn, *args, **kwargs):

And that's also rubbish. The right place for the fcn parameter is the
decorator function itself, exactly where it already is.

Whatever crack I was smoking yesterday, it must have been pretty awful


More information about the Python-list mailing list