On Sat, 2 Sept 2023 at 08:44, 'Martin R' via sage-devel <sage-devel@googlegroups.com> wrote: > > If I understand correctly, in python3 it is no longer necessary to implement > __ne__, if it is simply the negation of __eq__. > > There are currently about 200 definitions of the form > > def __ne__(self, other): > return not (self == other) > > I think it would be good to remove them.
SymPy removed most of its __ne__ methods but a few had to be kept. The exception is that if any superclass defines __ne__ then a subclass that overrides __eq__ must also override __ne__ to keep them consistent. Obviously if you control both classes then you can remove __ne__ from both but in SymPy's case some classes subclass builtin types that cannot be changed: class PolyElement(dict): def __eq__(self, other): # override dict.__eq__ def __ne__(self, other): # also need to override dict.__ne__ I don't know if that applies to any of the 200 __ne__ methods in Sage but I would check the mro in each case before removing __ne__. It is easy for this sort of thing to be overlooked in test code and in fact messing with __eq__/__ne__ (more so __eq__) can invalidate much of the test suite so I would tread carefully. -- Oscar -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/CAHVvXxQ9Ab9FoFLT5Amn7NMErt43oO0CCeSDOWk4MTqDfbkGnQ%40mail.gmail.com.