[Python-ideas] Before and after the colon in funciton defs.
ericsnowcurrently at gmail.com
Thu Sep 22 04:31:32 CEST 2011
On Wed, Sep 21, 2011 at 7:01 PM, Jan Kaliszewski <zuo at chopin.edu.pl> wrote:
> I'm adding both new propositions:
> 1. the `def foo(...) [len=len]:` syntax,
> 2. the `len = (static len)` expression syntax
> -- to the PEP-draft I'm preparing -- which Nick suggested in June
> (I'm sorry that that preparing lasts so much time, but my everyday-
> -activity-CPU has been overloaded a bit for a few months...).
> Ad 1: I think it's better than the `after-**` proposition from June,
> though still has some its drawbacks (Sven just mentioned some of them).
> Ad 2: I must admit that this one becomes my favorite syntax for
> early binding (though I don't like the abbreviated form '(i=i)').
> IMHO it's not only clear (no all that questions about assignment
> semantics) but also elegant, explicit and consistent with some existing
> syntax constructs (especially with `yield EXPR`).
> Note that (as you can use any expression) it makes possible to use e.g.
> tuples of several names:
> spam, print, open = static (len, print, open)
> Big +1 from me.
Agreed, though the the keyword should be on the LHS:
static spam, print, open = len, print, open
It's more consistent with other keywords that way and easier to spot
when reading code.
Also, "static" as a keyword is in use as an identifier in a number of
places per google's codesearch (on the order of 100) including in
Django. It's not like it's in super broad use, but it is in use.
> 3. Another variant could be with a colon (a bit similar to the lambda
> len = static: len
> spam, print, open = static: (spam, print, open)
> or even (reusing the existing keyword):
> len = def: len
> spam, print, open = def: (spam, print, open)
> (here "def" means: "at definition time")
> But I'd rather prefer the #2.
> Python-ideas mailing list
> Python-ideas at python.org
More information about the Python-ideas