
On 2021-12-01 at 17:16:34 +1100, Chris Angelico <rosuav@gmail.com> wrote:
*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?
No. I understand the arguments (pun intended) for the proposal, but I find none of them compelling.
2) Independently: Is the syntactic distinction between "=" and "=>" a cognitive burden?
No. The biggest cognitive burden I have with either is the lack of white space around the = or =>, but that's a different problem.
(It's absolutely valid to say "yes" and "yes", and feel free to say which of those pulls is the stronger one.)
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?
That depends on what you mean by "use." I wouldn't *write* code that uses it (I can't find many (if any) cases of (a), (b), or (c) in my code), but I would have to *read* other people's code that does. FWIW, the PEP doesn't mention mutability or mutable values at all. Also FWIW, I still think that if you're doing (b) or (c), then you're *not* doing default values anymore, you're moving pieces of the logic or the design into the wrong place. One example of (b) goes something like this: def write_to_log(event, time=>current_time()): actually_write_to_log(event, time) IOW, default to the current time, but allow the caller to specify a some other time instead. Maybe I'm old school, or overly pedantic, but IMO, those are two different use cases, and there should be two separate functions (potentially with separate authorization and/or notations in the log, or maybe I've spent too much time deciphering badly designed logs and log entries). *Maybe* a better example would be something like this: def write_to_log(event, id=>generate_appropriate_uuid()): actually_write_to_log(event, id) but I would still personally rather (for testability and maintainability reasons) write two functions, even (or perhaps especially) if they both called a common lower-level function to do the actual work.
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.)
No.
5) Do you know how to compile CPython from source, and would you be willing to try this out? Please? :)
Yes, and no. (Seriously: Apparently, I don't create APIs, in any language, that would/could/might benefit from late binding default values. What would I be trying?)