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

(cherry picked from commit 2a4d8c0a9e)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
This commit is contained in:
Miss Islington (bot) 2023-04-03 16:01:31 -07:00 committed by GitHub
parent cf72cc25f6
commit 5342f5e713
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 14 deletions

View file

@ -2787,6 +2787,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"