On Mon, 2021-10-25 at 03:47 +1100, Chris Angelico wrote:
> On Mon, Oct 25, 2021 at 3:43 AM Jonathan Fine <jfine2...@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?:

    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?

Cheers,

Sebastian


> 
> ChrisA
> _______________________________________________
> 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/YVE5PMBV5A7PLX242TMMQH2LW4YL2DXK/
> Code of Conduct: http://python.org/psf/codeofconduct/
> 

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
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/6S3AZEL3QIRJGM7CRRXBQYSIJB3KOJJT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to