[Python-ideas] Quick idea: defining variables from functions that take the variable name
Nick Coghlan
ncoghlan at gmail.com
Tue Jun 7 15:49:01 EDT 2016
On 7 June 2016 at 11:29, M.-A. Lemburg <mal at egenix.com> wrote:
> One approach would be to define what a decorator means in front
> of an expression (since that's currently a SyntaxError), without
> adding any new syntactic sugar. Here's a sketch...
>
> @decorator
> x = obj
>
> compiles to:
>
> x = obj
> decorator('x', obj, lineno)
As a possible guide to designing the signatures for binding
decorators, it's probably worth asking what would be needed to make:
@bindfunction
f = lambda : None
equivalent to:
def f(): pass
Since the interpreter already sets __module__ and __globals__
correctly on lambda functions, the main considerations would be to get
f.__name__ and f.__qualname__ set correctly, which means just the
immediate target would be insufficient - you'd also want the scope
naming information that gets included in __qualname__, but is omitted
from __name__.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list