[Python-ideas] Default decorator?

Tony Lownds tony at PageDNA.com
Thu Jan 17 02:16:37 CET 2008

On Jan 16, 2008, at 4:31 PM, Guido van Rossum wrote:

> Peter Norvig suggested an idea to me over lunch: a "default
> decorator". This would be something you could set once per module and
> it would be invoked for each function definition in the same way as a
> decorator is invoked, before any explicit decorators. His use case was
> something that wraps every function that uses argument annotations
> with something that interprets those annotations in a certain way and
> enforces that interpretation. It would save having to explicitly
> annotate every function or method that way.
> Thoughts? I suggested that a metaclass could do this for methods, but
> that of course leaves plain functions in the lurch.

Great idea. +1 on a "default decorator".

Like the global __metaclass__, I'd hope that it could apply to functions
nested in classes, but not functions nested in functions.

A lot of the same reasons for __metaclass__ apply to __decorator__:

"The potential uses for metaclasses are boundless. Some ideas that have
been explored including logging, interface checking, automatic  
automatic property creation, proxies, frameworks, and automatic resource



More information about the Python-ideas mailing list