[Python-ideas] Quick idea: defining variables from functions that take the variable name
Brendan Barnwell
brenbarn at brenbarn.net
Wed Jun 1 21:40:18 EDT 2016
On 2016-06-01 16:50, Jonathan Goble wrote:
> I have a completely different idea here. Forget clunky syntax,
> overloading of 'def' and 'as', and all that. Introduce the magic
> parameter '$'. To wit:
>
> def func(*args, **kwargs, $): # positioning of the $ is discussed
> below
> ... # function code here
>
> $ would be a special-cased parameter that does not receive an explicit
> argument, and is thus ignored when calling the function (i.e. the
> function above would be called simply as 'func(*args, **kwargs)').
> Instead, the $ parameter receives as its value a string representing the
> name that the function's return value will be bound to, or None if the
> function is called as a statement (where the return value is simply
> thrown away).
I think that's way too general and dangerous. I don't want arbitrary
objects to be able to do arbitrary things based on what name I'm
assigning them to. I think the fact that Python doesn't allow
overriding simple assignment, although it makes some things difficult,
makes it simpler to reason about in many cases. If we do add something
to handle this case, I'd rather it be something explicit, so you know
when you're crossing the barrier between identifiers and string values.
--
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