mirror of
https://github.com/python/cpython.git
synced 2025-09-03 15:31:08 +00:00
gh-116040: [Enum] fix by-value calls when second value is falsey; e.g. Cardinal(1, 0) (GH-116072)
This commit is contained in:
parent
b2d74cdbcd
commit
13ffd4bd9f
3 changed files with 35 additions and 4 deletions
|
@ -3409,6 +3409,15 @@ class TestSpecial(unittest.TestCase):
|
|||
self.assertIs(Types(2), Types.NetList)
|
||||
self.assertIs(Types('nl'), Types.NetList)
|
||||
|
||||
def test_second_tuple_item_is_falsey(self):
|
||||
class Cardinal(Enum):
|
||||
RIGHT = (1, 0)
|
||||
UP = (0, 1)
|
||||
LEFT = (-1, 0)
|
||||
DOWN = (0, -1)
|
||||
self.assertIs(Cardinal(1, 0), Cardinal.RIGHT)
|
||||
self.assertIs(Cardinal(-1, 0), Cardinal.LEFT)
|
||||
|
||||
def test_no_members(self):
|
||||
with self.assertRaisesRegex(
|
||||
TypeError,
|
||||
|
@ -3421,6 +3430,20 @@ class TestSpecial(unittest.TestCase):
|
|||
):
|
||||
Flag(7)
|
||||
|
||||
def test_empty_names(self):
|
||||
for nothing, e_type in (
|
||||
('', None),
|
||||
('', int),
|
||||
([], None),
|
||||
([], int),
|
||||
({}, None),
|
||||
({}, int),
|
||||
):
|
||||
empty_enum = Enum('empty_enum', nothing, type=e_type)
|
||||
self.assertEqual(len(empty_enum), 0)
|
||||
self.assertRaises(TypeError, 'has no members', empty_enum, 0)
|
||||
|
||||
|
||||
class TestOrder(unittest.TestCase):
|
||||
"test usage of the `_order_` attribute"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue