[Python-ideas] Quick idea: defining variables from functions that take the variable name
Brendan Barnwell
brenbarn at brenbarn.net
Wed Jun 1 14:05:42 EDT 2016
On 2016-06-01 06:29, Sven R. Kunze wrote:
> Another possibility would be (requiring no syntax change):
>
> name = function(args)
>
> would always be expanded to
>
> name = function(args)
> name.__name__ = "name"
I'm really against approaches like this that involve explicitly setting
a special dunder attribute. What I want from this syntax is for the RHS
expression to be able to use the string value of the variable name in
whatever way it wants to; restricting it to setting a hard-coded dunder
name is not solving the problem. What if, for instance, `function` is a
factory function that defines a class at runtime, and that class has its
own __name__, but the class (or `function`) wants to use the variable
name for something else?
--
Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is no
path, and leave a trail."
--author unknown
More information about the Python-ideas
mailing list