[Python-Dev] decorator module in stdlib?

Nick Coghlan ncoghlan at gmail.com
Thu Apr 9 14:11:28 CEST 2009

Michele Simionato wrote:
> On Wed, Apr 8, 2009 at 7:51 PM, Guido van Rossum <guido at python.org> wrote:
>> There was a remark (though perhaps meant humorously) in Michele's page
>> about decorators that worried me too: "For instance, typical
>> implementations of decorators involve nested functions, and we all
>> know that flat is better than nested." I find the nested-function
>> pattern very clear and easy to grasp, whereas I find using another
>> decorator (a meta-decorator?) to hide this pattern unnecessarily
>> obscuring what's going on.
> I understand your point and I will freely admit that I have always had mixed
> feelings about the advantages of a meta decorator with
> respect to plain simple nested functions. I see pros and contras.
> If functools.update_wrapper could preserve the signature I
> would probably use it over the decorator module.

Yep, update_wrapper was a compromise along the lines of "well, at least
we can make sure the relevant metadata refers to the original function
rather than the relatively uninteresting wrapper, even if the signature
itself is lost". The idea being that you can often figure out the
signature from the doc string even when introspection has been broken by
an intervening wrapper.

One of my hopes for PEP 362 was that I would be able to just add
__signature__ to the list of copied attributes, but that PEP is
currently short a champion to work through the process of resolving the
open issues and creating an up to date patch (Brett ended up with too
many things on his plate so he wasn't able to do it, and nobody else has
offered to take it over).


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list