mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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:
parent
cf72cc25f6
commit
5342f5e713
3 changed files with 32 additions and 14 deletions
|
@ -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"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue