
On Mon, Oct 25, 2021 at 3:12 PM Sebastian Berg <sebastian@sipsolutions.net> wrote:
On Mon, 2021-10-25 at 03:47 +1100, Chris Angelico wrote:
On Mon, Oct 25, 2021 at 3:43 AM Jonathan Fine <jfine2358@gmail.com> wrote:
Hi
Please forgive me if it's not already been considered. Is the following valid syntax, and if so what's the semantics? Here it is:
def puzzle(*, a=>b+1, b=>a+1): return a, b
Aside: In a functional programming language a = b + 1 b = a + 1 would be a syntax (or at least compile time) error.
I was about to ask about this. But also, how does that go together with non-required arguments?
def function(arr=>np.asarray(arr)): pass
Would seem like something we may be inclined to write instead of:
def function(arr): arr = np.asarray(arr)
(if that is legal syntax). In that case `arr` is a required parameter. Which then means that you cannot do it for optional parameters?:
This is all about argument defaults, not transforming values that were passed in. So if you pass a value, you always get exactly that value.
def function(arr1=>np.asarray(arr), arr2=>something): arr2 = np.asarray(arr2) # in case arr2 was passed in
Which is fair, but feels like a slightly weird difference in usage between required and optional arguments?
There are two possibilities: either it's a SyntaxError, or it's a run-time UnboundLocalError if you omit both of them (in which case it would be perfectly legal and sensible if you specify one of them).
I'm currently inclined towards SyntaxError, since permitting it would open up some hard-to-track-down bugs, but am open to suggestions about how it would be of value to permit this.
Not sure that I am scared of this if it gives a clear exception:
Parameter `a` was not passed, but it can only be omitted when parameter `b` is passed.
Not as clear (or complete) as a custom message, but not terrible?
A tad complicated and would require some hairy analysis. Also, I don't really want to encourage argument defaults that depend on each other :) ChrisA