diff options
-rw-r--r-- | Lib/enum.py | 5 | ||||
-rw-r--r-- | Lib/test/test_enum.py | 11 |
2 files changed, 11 insertions, 5 deletions
diff --git a/Lib/enum.py b/Lib/enum.py index 7ca8503..7d58f8d 100644 --- a/Lib/enum.py +++ b/Lib/enum.py @@ -447,11 +447,6 @@ class Enum(metaclass=EnumMeta): return (['__class__', '__doc__', '__module__', 'name', 'value'] + added_behavior) - def __eq__(self, other): - if type(other) is self.__class__: - return self is other - return NotImplemented - def __format__(self, format_spec): # mixed-in Enums should use the mixed-in type's __format__, otherwise # we can get strange results with the Enum name showing up instead of diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index d5a31b8..03f0e5d 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -1030,6 +1030,15 @@ class TestEnum(unittest.TestCase): self.assertEqual(list(Color), [Color.red, Color.green, Color.blue]) self.assertEqual(list(map(int, Color)), [1, 2, 3]) + def test_equality(self): + class AlwaysEqual: + def __eq__(self, other): + return True + class OrdinaryEnum(Enum): + a = 1 + self.assertEqual(AlwaysEqual(), OrdinaryEnum.a) + self.assertEqual(OrdinaryEnum.a, AlwaysEqual()) + def test_ordered_mixin(self): class OrderedEnum(Enum): def __ge__(self, other): @@ -1058,6 +1067,8 @@ class TestEnum(unittest.TestCase): self.assertLessEqual(Grade.F, Grade.C) self.assertLess(Grade.D, Grade.A) self.assertGreaterEqual(Grade.B, Grade.B) + self.assertEqual(Grade.B, Grade.B) + self.assertNotEqual(Grade.C, Grade.D) def test_extending2(self): class Shade(Enum): |