Using `or?` as the null coalescing operator

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? {} The rationale behind is to let `or` do its job with “truthy” values, while `or?` would require non-None values. The rest of the PEP looks good to me. I apologise in advance if this was already proposed and I missed it. Regards, Alessio

On 25 September 2015 at 09:07, Alessio Bogon <youtux@gmail.com> wrote:
It hasn't been suggested that I recall, and yes, I also prefer it to the doubled ?? spelling. One concrete advantage is that it helps convey that this is a short-circuiting control flow operator like 'and' and 'or' rather than a normal binary operator that always evaluates both operands. Regards, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia

On 28 September 2015 at 20:50, Koos Zevenhoven <k7hoven@gmail.com> wrote:
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 []". Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia

On 25 September 2015 at 09:07, Alessio Bogon <youtux@gmail.com> wrote:
It hasn't been suggested that I recall, and yes, I also prefer it to the doubled ?? spelling. One concrete advantage is that it helps convey that this is a short-circuiting control flow operator like 'and' and 'or' rather than a normal binary operator that always evaluates both operands. Regards, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia

On 28 September 2015 at 20:50, Koos Zevenhoven <k7hoven@gmail.com> wrote:
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 []". Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
participants (4)
-
Alessio Bogon
-
Koos Zevenhoven
-
Nick Coghlan
-
Ryan Gonzalez