Skip to content

Commit

Permalink
[3.12] gh-116040: [Enum] fix test_empty_names test (GH-116508) (GH-11…
Browse files Browse the repository at this point in the history
…6619)

* and fix _not_given usage

(cherry picked from commit 3c0dcef)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
  • Loading branch information
miss-islington and ethanfurman committed Mar 11, 2024
1 parent 1231697 commit 8b3b5be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
4 changes: 1 addition & 3 deletions Lib/enum.py
Expand Up @@ -169,8 +169,6 @@ def _dedent(text):
class _not_given:
def __repr__(self):
return('<not given>')
def __bool__(self):
return False
_not_given = _not_given()

class _auto_null:
Expand Down Expand Up @@ -765,7 +763,7 @@ def __call__(cls, value, names=_not_given, *values, module=None, qualname=None,
)
return cls._create_(
class_name=value,
names=names or None,
names=None if names is _not_given else names,
module=module,
qualname=qualname,
type=type,
Expand Down
18 changes: 7 additions & 11 deletions Lib/test/test_enum.py
Expand Up @@ -3334,17 +3334,13 @@ def test_no_members(self):
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)
for nothing in '', [], {}:
for e_type in None, int:
empty_enum = Enum('empty_enum', nothing, type=e_type)
self.assertEqual(len(empty_enum), 0)
self.assertRaisesRegex(TypeError, 'has no members', empty_enum, 0)
self.assertRaisesRegex(TypeError, '.int. object is not iterable', Enum, 'bad_enum', names=0)
self.assertRaisesRegex(TypeError, '.int. object is not iterable', Enum, 'bad_enum', 0, type=int)


class TestOrder(unittest.TestCase):
Expand Down

0 comments on commit 8b3b5be

Please sign in to comment.