On Thu, Jul 20, 2023, 01:19 Rob Cliffe via Python-ideas <
python-ideas@python.org> wrote:

>
>
> On 15/07/2023 21:08, Dom Grigonis wrote:
>
> Just to add. I haven’t thought about evaluation. Thus, to prevent
> evaluation of unnecessary code, introduction of C-style expression is
> needed anyways:
>
> 1. result = bar is None ? default : bar
>
>
> The below would have to evaluate all arguments, thus not achieving
> benefits of PEP505.
>
> 2. result = ifelse(bar is None, default, bar)
>
>
>
> So I would vote for something similar to:
>
> result = bar is None ? default : bar
>
>
> Where default and bar is only evaluated if needed. Although not to the
> extent as initially intended, it would offer satisfiable solutions to
> several proposals.
>
> Well, default is only evaluated if needed; bar is always evaluated.
> What is wrong with the Python equivalent
>
> result = default if bar is None else bar
> or if you prefer
> result = bar if bar is not None else default
>

Note also that when the condition is a truthiness check -- admittedly not
always the case, but it does occur reasonably often -- this can be
simplified further to:

  result = bar or default

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

Reply via email to