[Python-ideas] Before and after the colon in funciton defs.

Steven D'Aprano steve at pearwood.info
Fri Sep 23 05:26:31 CEST 2011

Devin Jeanpierre wrote:
>>  Yes, you're right that this can't be done with today's decorators.
> It can work with today's decorators and today's syntax, it just requires magic.
> (Magic doesn't mean "impossible things", it means "things that go
> below the expected level of abstraction". In this case, things like
> directly inspecting fields of the function object and creating a new
> one with modified fields -- that, or else mutating a
> supposedly-immutable object (also possible))

In this case, I believe that most of the work that needs to be done -- 
making a copy of the function and code object -- are not magic. They are 
fully supported in standard Python. The only "magic" is manipulating the 
bytecode of the code object to that it turns some globals into locals.

> That doesn't blow down the whole idea of $ special syntactic
> decorators, though. And maybe even this case is good for them.

I don't see any reason to introduce extra syntax for a different sort of 
decorator. What benefit is there? I think this $ proposal actually 
undermines the argument I am trying to make. A big advantage of using a 
decorator is that it requires no new syntax and no magic symbols beyond 
the standard @ symbol. The argument "yes, I like decorators, but I want 
to use $ instead of @" doesn't really help.

> I still like real decorators because they can be applied at run-time
> instead of just compile-time, which gives them additional use-cases.

I have negative interest in a "magic decorator" that can only work at 
compile time. If we're going to have that (unnecessary, in my opinion) 
limitation, then I prefer the static declaration proposal.


More information about the Python-ideas mailing list