On Tue, Oct 26, 2021 at 5:24 PM Chris Angelico <[email protected]> wrote:

> > How could that be avoided? by definition, early bound is evaluated
> "earlier" than  late-bound :-)
> >
> > This could cause a bit of confusion with "getting" that it's not a
> simple left-to-right rule, but that's the same potential confusion with
> early vs late bound parameters anyway.
>

sorry, got tangled up between "evaluating" and "name binding"


> The question is whether code like this should work:
>
> def f(a=>b + 1, b=2): ...
>
> f()
> f(b=4)
>
> Pure left-to-right assignment would raise UnboundLocalError in both
> cases. Tiered evaluation wouldn't.
>

Nice, simple example. I'm not a newbie, but my students are, and I think
they'd find "tiered" evaluation really confusing.

Are there any other places in Python where assignments aren't done
> left to right, but are done in two distinct phases?
>

I sure can't think of one.

I've been thinking about this from the perspective of a teacher or Python.
I"m not looking forward to having one more thing to teach about function
definitions -- I struggle enough with cover all of the *args, **kwargs,
keyword-only, positional-only options.

Python used to be such a simple language, not so much anymore :-(

That being said, we currently have to teach, fairly early on, the
consequences of using a mutable as a default value. And this PEP would make
that easier to cover. But I think it's really important to keep the
semantics as simple as possible, and left-to-right name binding is they way
to do that.

(all this complicated by the fact that there is a LOT of code and advice in
the wild about the None idiom, but what can you do?)

-CHB


-- 
Christopher Barker, PhD (Chris)

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/C5O7JBYNLCVBQGVGJMIKKVLJ4XFCFNJR/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to