[Python-ideas] [Suspected Spam] Re: Short form for keyword arguments and dicts

Stephen J. Turnbull turnbull at sk.tsukuba.ac.jp
Tue Jun 25 09:15:18 CEST 2013


Anders Hovmöller writes:

 >> I'll take the explicit use of locals any time.

I meant "locals" the function.  I should have written "locals()".

 > My suggestion isn't about introducing more magic, just a little bit
 > of convenience

It's syntax, which is always magic, or, if you prefer, "has arbitrary
semantics which must be memorized".  As syntax, it's ugly (IMO) and
nonintuitive (by the rationale that "=" is an infix binary relation or
assignment operator, not a unary prefix operator).  Not to forget
redundant, given the existence of locals() and positional arguments.

 > for two common use cases: passing along variables with the
 > same name to another function

If the two functions were designed with similar signatures, using
positional arguments is the obvious way to indicate this, at a saving
of one "=" per argument.  If they weren't and you don't feel like
looking up the signature of the function you're calling (or are
worried that the signature might change in a future version),
**locals() wins at the expense of bringing in (possibly) a bunch of
junk you don't want.  But it's way shorter than a sequence of even
*three* =-prefixed variable names (unless they're "x", "y", and "z").

I don't see a win here big enough to justify syntax, let alone *this*
syntax.

 > and throwing a bunch of variables into a dict (which is basically
 > the same thing since "dict(foo=foo)" == "{'foo': foo}"). 

This is a little more plausible, since you can't pun on the names of
the parameters when using positional arguments, since dicts don't have
positional arguments.  Still, adding syntax is a high hurdle.



More information about the Python-ideas mailing list