On Sun., 1 Nov. 2020, 3:01 pm Guido van Rossum, <gu...@python.org> wrote:

> On Sat, Oct 31, 2020 at 21:48 Dan Stromberg <drsali...@gmail.com> wrote:
>
>>
>> On Sat, Oct 31, 2020 at 9:37 PM Guido van Rossum <gu...@python.org>
>> wrote:
>>
>>>
>>> I think this over-stresses the notion that users might want to override
>>> the comparison operator to be used. We only have two operators that make
>>> sense in this context, 'is' and '==', and really, for almost everything you
>>> want to do, '==' is the appropriate operator. (There is a small trickle of
>>> bugs caused by people inappropriately using e.g. `if x is 1` instead of `if
>>> x == 1`, suggesting that if anything, there is too much freedom here.) The
>>> big exception is `None`, where you basically always want to use `is`, which
>>> is what PEP 634 does.
>>>
>>
> FWIW, there's an additional exception:
>>     sentinel = object()
>>
>>     if var is sentinel:
>>
>> I use this idiom from time to time - instead of None.
>>
>
> You can just write ‘case sentinel’, since object’s == operator uses
> identity anyway.
>

No, you can't, as the other operand might decide it wants to compare equal
to your sentinel value.

Cheers,
Nick.


-- 
> --Guido (mobile)
>
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/OSBJP7UTG6VFROJSS5ORKHXYOUZYVCKD/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to