changeset 45:8a560e0c3180

Implement __ne__ also where __eq__ is implemented
author Franz Glasner <f.glasner@feldmann-mg.com>
date Wed, 02 Aug 2023 13:58:25 +0200
parents ea8c2d01a9d9
children 92ae1e882cef
files data_schema/__init__.py
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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)