
On Wed, Oct 27, 2021 at 11:17 AM Christopher Barker <pythonchb@gmail.com> wrote:
On Tue, Oct 26, 2021 at 4:46 PM Rob Cliffe via Python-ideas <python-ideas@python.org> wrote:
There has been support for evaluating all early-bound defaults before all late-bound defaults. I have been persuaded that this is a reasonable option.
How could that be avoided? by definition, early bound is evaluated "earlier" than late-bound :-)
early-bound (i.e. regular) parameters are evaluated at function definition time. But the time we get to the late-bound ones, those are actual values, not expressions.
The interpreter could notice that early bound names are used in late-bound expressions and raise an error, but if not, there'd be no issue with when they were evaluated.
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.
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. Are there any other places in Python where assignments aren't done left to right, but are done in two distinct phases? ChrisA