[Python-ideas] Default decorator?

Guido van Rossum guido at python.org
Thu Jan 17 18:35:37 CET 2008

Quick response: this was already discussed, the requirement is for
this to happen to *any* def or lambda *before* applying decorators and
*regardless* of where/how they are nested (e.g. methods, nested
functions, etc.).


On Jan 17, 2008 7:16 AM, Jim Jewett <jimjjewett at gmail.com> wrote:
> On 1/16/08, Guido van Rossum <guido at python.org> wrote:
> > Peter Norvig suggested ... "default decorator". ...
> > set once per module and ... invoked, before any explicit decorators.
> > His use case ... uses argument annotations
> I would prefer that it be easier to control module creation in general.
> The decorator does meet his use case (and
> logging/tracing/registration), but there are varieties that would work
> better if the decorator were applied after any explicit decorators.
> (OTOH, doing that all the time raises the problem about whether
> decorators commute.)  There are already questions about whether it
> should apply to nested functions or lambdas.
> You can just settle those questions by fiat and meet 90% of the need,
> but letting the module control it seems cleaner (and also allows other
> extensions, such as alternate module dict representations).
> As to how module creation should be controlled -- that is a bit
> hairier.  My strawman is a __moduleclass__ analogous to __metaclass__.
> myfile.py:
>     __moduleclass__=altmod.mod1
> would be the moral equivalent of (some other file) running
>     import sys
>     import altmod
>     sys.modules["myfile"]=altmod.mod1()
>     exec myfile in sys.modules["myfile"]
> -jJ

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-ideas mailing list