mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
[3.13] gh-125259: Fix error notes removal in enum initialization (GH-125647) (GH-125858)
gh-125259: Fix error notes removal in enum initialization (GH-125647)
(cherry picked from commit 34653bba64
)
Co-authored-by: Mario Šaško <mariosasko777@gmail.com>
This commit is contained in:
parent
083c5814c8
commit
32830cf703
3 changed files with 25 additions and 11 deletions
|
@ -1902,6 +1902,25 @@ class TestSpecial(unittest.TestCase):
|
|||
class Wrong(Enum, str):
|
||||
NotHere = 'error before this point'
|
||||
|
||||
def test_raise_custom_error_on_creation(self):
|
||||
class InvalidRgbColorError(ValueError):
|
||||
def __init__(self, r, g, b):
|
||||
self.r = r
|
||||
self.g = g
|
||||
self.b = b
|
||||
super().__init__(f'({r}, {g}, {b}) is not a valid RGB color')
|
||||
|
||||
with self.assertRaises(InvalidRgbColorError):
|
||||
class RgbColor(Enum):
|
||||
RED = (255, 0, 0)
|
||||
GREEN = (0, 255, 0)
|
||||
BLUE = (0, 0, 255)
|
||||
INVALID = (256, 0, 0)
|
||||
|
||||
def __init__(self, r, g, b):
|
||||
if not all(0 <= val <= 255 for val in (r, g, b)):
|
||||
raise InvalidRgbColorError(r, g, b)
|
||||
|
||||
def test_intenum_transitivity(self):
|
||||
class number(IntEnum):
|
||||
one = 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue