On Sun, Oct 24, 2021 at 3:51 PM Brendan Barnwell <brenbarn@brenbarn.net> wrote:
On 2021-10-23 09:07, Chris Angelico wrote:
Proposal: Proper syntax and support for late-bound argument defaults.
def spaminate(thing, count=:thing.getdefault()): ...
I'm -1 on it.
For me the biggest problem with this idea is that it only handles a subset of cases, namely those that can be expressed as an expression inlined into the function definition. This subset is too small, because we'll still have to write code in the function body for cases where the default depends on more complex logic. But it is also too large, because it will encourage people to cram complex expressions into the function definition. ... Also, insofar as glancing at the function signature is useful, I suspect that putting this change in will *also* lead to help() being unhelpful, because, as I mentioned above, if the default uses anything but the most trivial logic, the signature will become cluttered with stuff that ought to be separated out as actual logic.
These two considerations, together, are the exact push that programmers need: keep the expression short, don't cram everything into the function definition. It's like writing a list comprehension; technically you can put any expression into the body of it, but it's normally going to be short enough to not get unwieldy. ChrisA