[Python-ideas] Quick idea: defining variables from functions that take the variable name

Stephen J. Turnbull stephen at xemacs.org
Tue May 31 14:58:36 EDT 2016

Steven D'Aprano writes:

 > > It give me no clue what it's supposed to mean.
 > That's harsh. No clue *at all*?

What harsh?  Frank, yes.

As for the question, of course not "*at all*", obviously it's an
operator that does something.  But what and to which, no clue, except
from the context of what you're trying to accomplish -- not from the
notation itself.

The variety of examples and hints you give just makes it worse.

 > And neither is the `self` argument to methods. But we learn that self is 
 > implicitly provided as if by magic :-)

No, it's explicitly provided by the attribute reference syntax that
binds a positional parameter when the attribute is a method.  Binding
positional parameters is a concept familiar from all programming
languages I know of (except Haskell, which has only one parameter so
"position" is a vacuous concept).  I will remind you that ".attribute"
syntax to avoid typing self in method definitions and similar
anaphoric syntaxes for avoiding typing the name of a object whose
attributes are repeatedly accessed have been repeatedly vetoed.

 > Another similar example of magic is decorator syntax:

I can't explain why that doesn't bother me, but it doesn't.  It's also
much more powerful.  Not the syntax itself, but what decorators can do.

 > The thing is, regardless of whether we use a symbol or a keyword, the 
 > functionality here is going to be magical. That's its point: it is to 
 > avoid the need to write the name twice.

Yes, I could learn this magic.  No, I find the syntaxes proposed so
far unintuitive, by which I mean quite arbitrary and lacking
connotations that lead to the intended meaning.  So, not good enough.

-1 on forward arrow syntax: as you point out, mention of a variable
injects that name into the appropriate namespace, and there's
important.  Extremely concise notation for variable evaluation is
incredibly important, and having that string in locals() or globals()
is necessary for introspection.  Thus variable *mention* does the

But the other syntaxes that inject names of identifiers into
namespaces are all statements.

-0.5 on keywords: this doesn't clear the bar for keyword introduction
yet AFAICS.  Not even if it's only used in stubfiles.

More information about the Python-ideas mailing list