Re:Upcoming Python features brought to you by Python Enhance...
by mrtranscendence on Monday February 14, 2022 @10:15AM
(#30332967)
Having the default value be None isn't great for documentation, and it isn't great for static typing, because now your argument has to be of type Union[Foo, None]. I've written functions where there are reasonably long chains of stuff like
if foo is None:
foo = []
and it'd be nice to be done with that.
Re:Upcoming Python features brought to you by Python Enhance...
by monkeybutton on Monday February 14, 2022 @10:20AM
(#30333044)
I see what you're saying about typing. As for the reasonably long chains of default initialization code. Well now its in the definition. You could have functions with more code defining the parameters than in body.
Re:Upcoming Python features brought to you by Python Enhance...
by tinalumfoil on Monday February 14, 2022 @10:21AM
(#30333054)
LWN had a good article on this: https://lwn.net/Articles/875441/
Short answer is these downsides were discussed but the proposal went ahead anyway.
Imo I'm with you. This type of syntax has a lot of implicit behavior where it's going to be difficult to find/fix bugs related to it.
Re:Upcoming Python features brought to you by Python Enhance...
by monkeybutton on Monday February 14, 2022 @07:40PM
(#30340881)
That was a great article, thank you for the link!
Re:Upcoming Python features brought to you by Python Enhance...
by dragonwriter on Monday February 14, 2022 @12:14PM
(#30334622)
> Why not just do `l = len(x) if l is None else l`?
Because dev tooling can “see” and present information from the argument list much more easily than analyzing downstream behavior.
> What about side effects?
Those happen whether or not the computation is visible in the signature (though its more obvious to the programmer of the consuming code if it is visible.)
Why not just do `l = len(x) if l is None else l`?
With the new syntax can you define defaults computed from other defaults? What about side effects? Why is computation happening in function args at all?!