gh-102549: [Enum] fail enum creation when data type raises in __init__ (GH-103149)

This commit is contained in:
Ethan Furman 2023-03-31 13:52:31 -07:00 committed by GitHub
parent dfc4c95762
commit 2a4d8c0a9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 14 deletions

View file

@ -2916,6 +2916,26 @@ class TestSpecial(unittest.TestCase):
self.assertEqual(FlagFromChar.a, 158456325028528675187087900672)
self.assertEqual(FlagFromChar.a|1, 158456325028528675187087900673)
def test_init_exception(self):
class Base:
def __init__(self, x):
raise ValueError("I don't like", x)
with self.assertRaises(TypeError):
class MyEnum(Base, enum.Enum):
A = 'a'
def __init__(self, y):
self.y = y
with self.assertRaises(ValueError):
class MyEnum(Base, enum.Enum):
A = 'a'
def __init__(self, y):
self.y = y
def __new__(cls, value):
member = Base.__new__(cls)
member._value_ = Base(value)
return member
class TestOrder(unittest.TestCase):
"test usage of the `_order_` attribute"