[Python-ideas] Default decorator?

Jim Jewett jimjjewett at gmail.com
Thu Jan 17 16:16:29 CET 2008


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



More information about the Python-ideas mailing list