Close #18545: now only executes member_type if no _value_ is assigned in __new__.

This commit is contained in:
Ethan Furman 2013-07-25 13:50:45 -07:00
parent 4d35e75ca0
commit b41803e3ef
2 changed files with 20 additions and 4 deletions

View file

@ -934,6 +934,22 @@ class TestEnum(unittest.TestCase):
self.assertEqual(ColorInAList.red.value, [1])
self.assertEqual(ColorInAList([1]), ColorInAList.red)
def test_conflicting_types_resolved_in_new(self):
class LabelledIntEnum(int, Enum):
def __new__(cls, *args):
value, label = args
obj = int.__new__(cls, value)
obj.label = label
obj._value_ = value
return obj
class LabelledList(LabelledIntEnum):
unprocessed = (1, "Unprocessed")
payment_complete = (2, "Payment Complete")
self.assertEqual(list(LabelledList), [LabelledList.unprocessed, LabelledList.payment_complete])
self.assertEqual(LabelledList.unprocessed, 1)
self.assertEqual(LabelledList(1), LabelledList.unprocessed)
class TestUnique(unittest.TestCase):