[Python-ideas] Default decorator?

Guido van Rossum guido at python.org
Thu Jan 17 02:06:08 CET 2008


On Jan 16, 2008 4:58 PM, Brett Cannon <brett at python.org> wrote:
>
> On Jan 16, 2008 4:31 PM, Guido van Rossum <guido at python.org> 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.
>
> Do we want something like a global decorator, or more something like
> __build_class__ for the 'def' statement (although a quick attempt at
> replacing __build_class__ didn't work for me)?

Wasn't __build_class__ only in an early version of PEP 3115?

> I personally prefer the
> latter as that is the more powerful solution between the two. Plus I
> don't see the need for a global decorator coming up often enough to
> warrant making it simpler.

The use case might come up a lot more if people take the argument
annotations idea and run with it. They might want to add lots of
annotations to lots of functions, and then have one convenient way to
ensure all those functions are wrapped by something that actually uses
the annotations for something (e.g. adaptation or type checking).

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



More information about the Python-ideas mailing list