[Python-ideas] Quick idea: defining variables from functions that take the variable name
Sven R. Kunze
srkunze at mail.de
Wed Jun 1 14:36:50 EDT 2016
On 01.06.2016 20:05, Brendan Barnwell wrote:
> 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?
>
Each of both approaches do have its own advantages and drawbacks.
It seems, I need to repeat myself: the post you quoted explicitly said
it does not care about the name of the dunder attribute. So, pick one
appropriate, like "__to_be_assigned_lhs_name__", which should not clash
with most usecases.
Furthermore, the same argument could be used against all dunder names.
Best,
Sven
More information about the Python-ideas
mailing list