[Python-ideas] Before and after the colon in funciton defs.

Ron Adam ron3200 at gmail.com
Thu Sep 22 05:44:20 CEST 2011

On Wed, 2011-09-21 at 20:31 -0600, Eric Snow wrote:
> 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
> > [http://mail.python.org/pipermail/python-ideas/2011-June/010569.html]
> > (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

The above could also be ...

     spam, print, open = (static len, print, open)

As Jan pointed out, it would be very similar to how the 'yield' is used.

It doesn't do anything to the identifiers on the left side.

The only thing the static expression does is save a reference to what
ever the expression part on the right evaluates to at the time the
function is defined.  Later, when the function is called, is when it's
actually used.

At define time...

     spam, print, open = static (len, print, open)

Becomes this at call time...

     spam, print, open = _tuple  #tuple created by static expression


(Apologies for any double or delayed posts, I'm still trying to get some
email glitches worked out.)

> 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.

More information about the Python-ideas mailing list