On Wednesday, December 1, 2021 at 1:18:33 AM UTC-5 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?

No, I would avoid for the sake of readers.  Anyway, it can't be used in any 
public projects until thy drop support for 3.10, which is many years off.

Also, I think this question is quite the biased sample on python-ideas. 
Please consider asking this to less advanced python users, e.g., 
reddit.com/r/python or learnpython. 

>
> 2) Independently: Is the syntactic distinction between "=" and "=>" a 
> cognitive burden? 
>
> (It's absolutely valid to say "yes" and "yes", and feel free to say 
> which of those pulls is the stronger one.)

 Yes.

>
>
> 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? 
>
> 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? :) 
>
> 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. 
>
> Any and all comments welcomed. I mean, this is python-ideas after 
> all... bikeshedding is what we do best! 

 


This PEP has a lot of interesting ideas.  I still think that none-aware 
operators (PEP 505) are an easier, more readable general solution to 
binding calculated default values to arguments succinctly.  I think the 
problems with this idea include:
* The caller cannot explicitly ask for default behaviour except by omitting 
the parameter.  This can be very annoying to set up when the parameter 
values are provided from other places, e.g.,
if need_x:
  # do lots of stuff
  x = whatever
else:
  # do more
  x = None
f(x=x, ...)  # easy, but with this PEP, you would have to find a way to 
remove x from the parameter list.  Typically, removing a parameter from a 
dynamically-created parameter list is hard.

* The function code becomes unreadable if the parameter-setting code is 
long.  Having a long piece of code inside the function after "if parameter 
is None" is just fine.  Having none-aware operators would make such code 
more succinct.

* People nearly always avoid writing code in the parameter defaults 
themselves, and this new practice adds a lot of cognitive load.  E.g., 
people rarely write:
def f(x: int = 1+g()) -> None: ...
Parameter lists are already busy enough with parameter names, annotations, 
and defaults.  We don't need to encourage this practice.

In short, I think this is a creative idea, a great exploration.  While 
optional parameters are common, and some of them have defaults that are 
calculated inside the function, my feeling is that people will continue to 
set their values inside the function.

Best,

Neil

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/HJIDYKZV3EVURWFLETSPIZ2YFGN2RNZE/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to