On Sun, Oct 24, 2021 at 05:40:55PM +0100, Jonathan Fine wrote:

> 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

We can consider that to be syntactic sugar for:

    def puzzle(*, a=None, b=None):
        if a is None:
            a = b+1
        if b is None:
            b = a+1

So that has a perfectly sensible interpretation:

- a is optional
- b is optional
- but you must supply at least one.

and should be perfectly legal. I see no reason to prohibit it.

(It would be nice if we could give a better exception, rather than just 
UnboundLocalError, but that's not essential.)


-- 
Steve
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/5LNLIDFKYZ4QPRS2ILDTUTGOPA6GRXEQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to