[Python-ideas] Using `or?` as the null coalescing operator

Nick Coghlan ncoghlan at gmail.com
Tue Sep 29 10:09:50 CEST 2015

On 28 September 2015 at 20:50, Koos Zevenhoven <k7hoven at gmail.com> wrote:
> On Mon, Sep 28, 2015 at 10:13 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> On 25 September 2015 at 09:07, Alessio Bogon <youtux at gmail.com> wrote:
>>> I really like PEP 0505. The only thing that does not convince me is the `??` operator. I would like to know what you think of an alternative like `or?`:
>>> a_list = some_list or? []
>>> a_dict = some_dict or? {}
> And have the following syntax options been considered?
> a_list = some_list else []

In addition to the syntactic ambiguity Ryan notes, there's no hint
here that we're using "some_list is not None" as the condition rather
than "bool(some_list)"

> a_list = some_list or [] if None

This one isn't supportable at the language grammar level - by the time
we get to the "if" token, the parser will have already interpreted the
first part as "some_list or []".


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list