[Mesa-dev] [PATCH 12/26] python: Fix unequality comparisons

Dylan Baker dylan at pnwbakers.com
Tue Aug 7 20:15:38 UTC 2018


Quoting Mathieu Bridon (2018-07-06 02:25:53)
> On Thu, 2018-07-05 at 09:10 -0700, Dylan Baker wrote:
> > Quoting Mathieu Bridon (2018-07-05 06:17:43) 
> > > +    def __ne__(self, other):
> > > +        return not self.__eq__(other)
> > 
> > This can be written as "not (self == other)", right?
> 
> It can, yes.
> 
> The `==` operator is going to end up calling the `__eq__` method
> defined just above anyway, and we're already in the implementation
> details of `__ne__`.
> 
> So it felt more natural to me to have `__ne__` be the opposite of
> `__eq__` rather than the opposite of `==`.
> 
> Also, `not (\u2026 == \u2026)` feels weird, it screams "replace me by `\u2026 != \u2026`".
> Which I'm worried someone not paying attention might do in the future.
> 
> I don't feel very strongly about it though, so I'll change it if you
> do.
> 
> 
> -- 
> Mathieu

I go back and forth on it. Calling dunder methods directly feels a little odd to
me, they're more of a protocol than actual methods. For a lot of dunder methods
I'd be very strongly against calling them directly (__iter__ and __next__ for
example), I guess for the comparison methods I can go either way.

Oh, I just noticed the commit message should say "inequality" instead of
"unequality".

Dylan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: signature
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20180807/62c0ba48/attachment.sig>


More information about the mesa-dev mailing list