Close #18989: enum members will no longer overwrite other attributes, nor be overwritten by them.

This commit is contained in:
Ethan Furman 2013-09-15 12:34:36 -07:00
parent defe7f4c62
commit 101e0746d3
3 changed files with 53 additions and 26 deletions

View file

@ -228,6 +228,32 @@ class TestEnum(unittest.TestCase):
['FALL', 'ANOTHER_SPRING'],
)
def test_duplicate_name(self):
with self.assertRaises(TypeError):
class Color(Enum):
red = 1
green = 2
blue = 3
red = 4
with self.assertRaises(TypeError):
class Color(Enum):
red = 1
green = 2
blue = 3
def red(self):
return 'red'
with self.assertRaises(TypeError):
class Color(Enum):
@property
def red(self):
return 'redder'
red = 1
green = 2
blue = 3
def test_enum_with_value_name(self):
class Huh(Enum):
name = 1
@ -618,17 +644,6 @@ class TestEnum(unittest.TestCase):
self.assertIsNot(type(whatever.really), whatever)
self.assertEqual(whatever.this.really(), 'no, not that')
def test_overwrite_enums(self):
class Why(Enum):
question = 1
answer = 2
propisition = 3
def question(self):
print(42)
self.assertIsNot(type(Why.question), Why)
self.assertNotIn(Why.question, Why._member_names_)
self.assertNotIn(Why.question, Why)
def test_wrong_inheritance_order(self):
with self.assertRaises(TypeError):
class Wrong(Enum, str):