# HG changeset patch # User Franz Glasner # Date 1690977505 -7200 # Node ID 8a560e0c31808ec907c4ecdb296ff05f18c4ecab # Parent ea8c2d01a9d978c00e87e7c7e72d4b292ef9004a Implement __ne__ also where __eq__ is implemented diff -r ea8c2d01a9d9 -r 8a560e0c3180 data_schema/__init__.py --- a/data_schema/__init__.py Wed Aug 02 09:31:49 2023 +0200 +++ b/data_schema/__init__.py Wed Aug 02 13:58:25 2023 +0200 @@ -237,6 +237,17 @@ and (self.cause == other.cause) and (self.index == other.index)) + def __ne__(self, other): + # + # While the default in Python3 is sensible implementing is recommended + # when a built-in __eq__ is overwritten (Raymond Hettinger). + # + # Do not use not self == other because NotImplemented is not handled + # properly in some early Python versions (including Py2). + # + equal = self.__eq__(other) + return NotImplemented if equal is NotImplemented else not equal + def __getstate__(self): return (1, self.code, self.severity, self.hint, self.context, self.cause, self.index)