Kaydet (Commit) be3c2fea authored tarafından Ethan Furman's avatar Ethan Furman

removed Enum.__eq__ as it added nothing

üst 82e9f32f
......@@ -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
......
......@@ -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):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment