
On 01/12/2021 06:16, Chris Angelico wrote:> I've just updated PEP 671 https://www.python.org/dev/peps/pep-0671/
with some additional information about the reference implementation, and some clarifications elsewhere.
*PEP 671: Syntax for late-bound function argument defaults*
Questions, for you all:
1) If this feature existed in Python 3.11 exactly as described, would you use it? Yes, absolutely.
2) Independently: Is the syntactic distinction between "=" and "=>" a cognitive burden? Well, I prefer to repurpose the walrus.
I think that is mostly because of my experience with Mathematica/Wolfram in which "=" means "bind now" and ":=" means "bind later" in a similar way to the proposal here. I understand there is possible ambiguity both with the walrus itself and with annotations, but to me it is less confusing than =>, especially in the face of its possible use as a new spelling for lambda, which might be a pretty common use-case for late binding.
3) If "yes" to question 1, would you use it for any/all of (a) mutable defaults, (b) referencing things that might have changed, (c) referencing other arguments, (d) something else? a) for sure; b) possibly; c) likely; d) who knows?
More on these: b) I think another motivation that hasn't been highlighted is teaching -- perhaps surprisingly, I think adding this will make some aspects of teaching *easier*. Mutable defaults are known to be confusing to Python neophytes; I have certainly found this when I have both explictly taught or just had to explain some aspect of python. Yes, I know that understanding this behaviour is exactly part of learning the meaning of "binding" in Python but nonetheless being able to contrast the two of these would actually be useful in making the distinction. c) I would probably use this, but can we confirm something that isn't explicit in the pep: Does this def fn(word, num=>len(word)):... mean the same as this? (except for the default for word): def fn(word="foo", num=>len(word):... I can't think of any argument they shouldn't but in fact the former reads funny to me. Also, relatedly, I assume that late-bound arguments can refer to names that only exist in the caller's environment, but haven't even been bound at definition time? And that if they are not bound at call time, there is a syntax error?
4) If "no" to question 1, is there some other spelling or other small change that WOULD mean you would use it? (Some examples in the PEP.
5) Do you know how to compile CPython from source, and would you be willing to try this out? Please? :)
I'd love to hear, also, from anyone's friends/family who know a bit of Python but haven't been involved in this discussion. If late-bound defaults "just make sense" to people, that would be highly informative. I am not a regular contributor so perhaps I already fit into this category; see also my comment about teaching above. Any and all comments welcomed. I mean, this is python-ideas after all... bikeshedding is what we do best!
The reference implementation currently has some test failures, which I'm looking into. I'm probably going to make this my personal default Python interpreter for a while, to see how things go.
ChrisA