PEP 318: Can't we all just get along?

Kevin Smith Kevin.Smith at sas.com
Wed Aug 18 09:01:06 EDT 2004


In <mailman.1834.1092791633.5135.python-list at python.org> Paul Morrow  
wrote:
> Peter Hansen wrote:
> > Questions (for Kevin):
> 
> 1. Would
> 
>        def deco1 foo(a, b, c): pass
> 
>     be the same as (just syntactic sugar for)
> 
>        def foo(a, b, c): pass
>        foo = deco1(foo)
> 
>     or would it mean something else?

Sorry, I guess I should have put the equivalent current Python code in 
my first post.  The example above is exactly what I meant.

 
> 2. Would
> 
>        def deco1 deco2 foo(a, b, c): pass
> 
>     be the same as
> 
>        def foo(a, b, c): pass
>        foo = deco1(deco2(foo))
> 
>     or
> 
>        def foo(a, b, c): pass
>        foo = deco2(deco1(foo))

I would choose the first option since it's easier to transform the 
string "deco1 deco2 foo" to "deco1(deco2(foo))" while I'm reading it (i.
e. it fits my head :) ).


> 3. Would there be any restrictions on what a decorator could *do* to 
> the  method it was passed?  e.g. Could it change:
>
>    * the method's name (which could of course affect the method's
>      visibility: public|private|semi-private)?

Nope, beginners wouldn't understand it immediately.  That's just too 
magical.

>    * whether the method was a static, class, or instance method?

Yes. 

>    * the method's signature (formal parameter names, parameter order,
>      defaults values)?

I guess, in theory, it could since the object returned by the 
"decorator" (I really hate that term) could return a completely 
different object, but I wouldn't suggest it.

-- 
Kevin Smith
Kevin.Smith at sas.com



More information about the Python-list mailing list