mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
removed Enum.__eq__ as it added nothing
This commit is contained in:
parent
82e9f32f17
commit
be3c2fea35
2 changed files with 11 additions and 5 deletions
|
@ -447,11 +447,6 @@ class Enum(metaclass=EnumMeta):
|
||||||
return (['__class__', '__doc__', '__module__', 'name', 'value'] +
|
return (['__class__', '__doc__', '__module__', 'name', 'value'] +
|
||||||
added_behavior)
|
added_behavior)
|
||||||
|
|
||||||
def __eq__(self, other):
|
|
||||||
if type(other) is self.__class__:
|
|
||||||
return self is other
|
|
||||||
return NotImplemented
|
|
||||||
|
|
||||||
def __format__(self, format_spec):
|
def __format__(self, format_spec):
|
||||||
# mixed-in Enums should use the mixed-in type's __format__, otherwise
|
# 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
|
# 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(Color), [Color.red, Color.green, Color.blue])
|
||||||
self.assertEqual(list(map(int, Color)), [1, 2, 3])
|
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):
|
def test_ordered_mixin(self):
|
||||||
class OrderedEnum(Enum):
|
class OrderedEnum(Enum):
|
||||||
def __ge__(self, other):
|
def __ge__(self, other):
|
||||||
|
@ -1058,6 +1067,8 @@ class TestEnum(unittest.TestCase):
|
||||||
self.assertLessEqual(Grade.F, Grade.C)
|
self.assertLessEqual(Grade.F, Grade.C)
|
||||||
self.assertLess(Grade.D, Grade.A)
|
self.assertLess(Grade.D, Grade.A)
|
||||||
self.assertGreaterEqual(Grade.B, Grade.B)
|
self.assertGreaterEqual(Grade.B, Grade.B)
|
||||||
|
self.assertEqual(Grade.B, Grade.B)
|
||||||
|
self.assertNotEqual(Grade.C, Grade.D)
|
||||||
|
|
||||||
def test_extending2(self):
|
def test_extending2(self):
|
||||||
class Shade(Enum):
|
class Shade(Enum):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue