
On Tue, Oct 26, 2021 at 01:32:58AM +0100, Rob Cliffe via Python-ideas wrote:
Syntax bikeshedding: I still favour var := expr
That clashes with the walrus operator. Remember that the walrus operator can appear inside the expression: var:=spam+eggs:=(something+other) or eggs Modifying the assignment symbol is wrong. This is not a new kind of assignment, it should use the same `=` regular assignment. We are tagging the parameter to use late-binding, not using a different sort of assignment. The tag should be on the parameter name, not the assignment.
IMO the similarity to early binding syntax is a good thing (or at least not a bad thing).
Right, because binding is binding, and we should use the same `=`.
Just as the walrus operator is similar to `=` - after all they are both a form of assignment.
But the walrus is a different form of assignment, it is an expression, not a statement. Function parameter defaults are not literally statements, they are declarations, which are a kind of statement.
I don't think argument defaults should be allowed to refer to later arguments (or of course the current argument). That's making the interpreter's task too complicated, not to mention (surely?) inefficient. And it's confusing.
Worst case, the interpreter has to do two passes over the parameters instead of one. The inefficiency is negligible. As for confusing, I think you are conflating "it's new" for "it is confusing". You aren't confused. I doubt that anyone capable of writing a Python function would be confused by the concept: def func(a=1, @b=c+1, c=2): is no more confusing than the status quo: def func(a=1, b=None, c=2): if b is None: b = c + 1 If you can understand the second, you can understand the first. All you have to remember is that: 1. positional arguments are bound to parameters first, left to right; 2. keyword arguments are bound to parameters next; 3. regular (early bound) defaults are bound next; 4. and lastly, late-bound defaults are bound. Easey-peasey. I really wish people would stop assuming that fellow Python coders are knuckle-dragging troglodytes incapable of learning behaviour equivalent to behaviour they have already learned: The status quo: 1. positional arguments are bound to parameters first, left to right; 2. keyword arguments are bound to parameters next; 3. regular (early bound) defaults are bound last. All we're doing is adding one more step. If that is confusing to people, wait until you discover classes and operator precedence! x = 2*3**4 - 1 Have some faith that coders aren't idiots. There are genuinely confusing features that are *inherently* complicated and complex, like threading, asynchronous code, metaclasses, the descriptor class, and we cope. But the idea that people won't be able to wrap their brains around the interpreter assigning defaults in four passes rather than three is not credible. 99% of the time you won't even think about it, and the one time in a hundred you do, it is simple. Early binding defaults are bound first, late binding defaults are bound as late as possible. (Maybe even as late as *on need* rather than before the body of the function is entered. That would be really nice, but maybe too hard to implement.) -- Steve