Why does __ne__ exist?

Chris Angelico rosuav at gmail.com
Mon Jan 8 00:26:51 EST 2018


On Mon, Jan 8, 2018 at 4:21 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
> On 01/07/2018 04:57 PM, Chris Angelico wrote:
>>
>> On Mon, Jan 8, 2018 at 11:35 AM, Ben Finney wrote:
>>>
>>> Chris Angelico writes:
>
>
>>>> Let's put it this way. Suppose that __eq__ existed and __ne__ didn't,
>>>> just like with __contains__. Go ahead: sell the notion of __ne__.
>>>> Pitch it, show why we absolutely need to allow this.
>>>
>>>
>>> I think “reject unless absolutely needed” is an unreasonably high bar,
>>> which would disqualify most Python language features. So I don't know
>>> why you expect this to be so especially strongly argued.
>>
>>
>> True, I exaggerated a bit. But do you think that, had __ne__ not
>> existed for years, its addition could be justified?
>
>
> Considering we just recently added a matrix-multiplication operator, yes.
>

That has approximately zero consequences on class authors. If you were
unaware of __matmul__, it wouldn't have the chance to randomly break
your __mul__ semantics. And even with that excellent backward
compatibility, it STILL took many years to get accepted.

ChrisA



More information about the Python-list mailing list