On 2021-10-23 23:33, Steven D'Aprano wrote:
On Sat, Oct 23, 2021 at 08:29:54PM -0700, Brendan Barnwell wrote:

        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.

True. But that's equally true for default values under early binding.
Would you say that existing syntax for default values is problematic
because it only covers the 90% of cases where the default value can be
computed from an expression?

If push comes to shove, we can always write a helper function.


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.

Just like they do now?

I understand your point, but there is an important difference between the current situation and the proposal. Right now, the function definition executes in the enclosing scope. That means that there is nothing you can do in a default-argument expression that you can't do by assigning to a variable in a separate line (or lines) before defining the function. But with this proposal, the function definition will gain the new ability to express logic that executes in the function body environment, with the restriction that it be only a single expression.

It's true that any feature can be abused, but I think this temptation to shoehorn function logic into the argument list will be more likely to result in unwieldy signatures than the current situation.

--
Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail."
   --author unknown
_______________________________________________
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/OYUT3DI7J57GX3EE4NKTL7L3NVSNCD5N/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to