mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
bpo-30616: Functional API of enum allows to create empty enums. (#2304)
* bpo-30616: Functional API of enum allows to create empty enums. * Update NEWS move addition to avoid conflict
This commit is contained in:
parent
5ff7132313
commit
dcc8ce44c7
3 changed files with 24 additions and 1 deletions
|
@ -381,7 +381,7 @@ class EnumMeta(type):
|
||||||
# special processing needed for names?
|
# special processing needed for names?
|
||||||
if isinstance(names, str):
|
if isinstance(names, str):
|
||||||
names = names.replace(',', ' ').split()
|
names = names.replace(',', ' ').split()
|
||||||
if isinstance(names, (tuple, list)) and isinstance(names[0], str):
|
if isinstance(names, (tuple, list)) and names and isinstance(names[0], str):
|
||||||
original_names, names = names, []
|
original_names, names = names, []
|
||||||
last_values = []
|
last_values = []
|
||||||
for count, name in enumerate(original_names):
|
for count, name in enumerate(original_names):
|
||||||
|
|
|
@ -2291,6 +2291,26 @@ class TestIntFlag(unittest.TestCase):
|
||||||
self.assertIs(type(e), Perm)
|
self.assertIs(type(e), Perm)
|
||||||
|
|
||||||
|
|
||||||
|
def test_programatic_function_from_empty_list(self):
|
||||||
|
Perm = enum.IntFlag('Perm', [])
|
||||||
|
lst = list(Perm)
|
||||||
|
self.assertEqual(len(lst), len(Perm))
|
||||||
|
self.assertEqual(len(Perm), 0, Perm)
|
||||||
|
Thing = enum.Enum('Thing', [])
|
||||||
|
lst = list(Thing)
|
||||||
|
self.assertEqual(len(lst), len(Thing))
|
||||||
|
self.assertEqual(len(Thing), 0, Thing)
|
||||||
|
|
||||||
|
|
||||||
|
def test_programatic_function_from_empty_tuple(self):
|
||||||
|
Perm = enum.IntFlag('Perm', ())
|
||||||
|
lst = list(Perm)
|
||||||
|
self.assertEqual(len(lst), len(Perm))
|
||||||
|
self.assertEqual(len(Perm), 0, Perm)
|
||||||
|
Thing = enum.Enum('Thing', ())
|
||||||
|
self.assertEqual(len(lst), len(Thing))
|
||||||
|
self.assertEqual(len(Thing), 0, Thing)
|
||||||
|
|
||||||
def test_containment(self):
|
def test_containment(self):
|
||||||
Perm = self.Perm
|
Perm = self.Perm
|
||||||
R, W, X = Perm
|
R, W, X = Perm
|
||||||
|
|
|
@ -385,6 +385,9 @@ Library
|
||||||
correctly returns the ``127.0.0.1`` host, instead of treating ``@evil.com``
|
correctly returns the ``127.0.0.1`` host, instead of treating ``@evil.com``
|
||||||
as the host in an authentification (``login@host``).
|
as the host in an authentification (``login@host``).
|
||||||
|
|
||||||
|
- bpo-30616: Functional API of enum allows to create empty enums.
|
||||||
|
Patched by Dong-hee Na
|
||||||
|
|
||||||
- bpo-30038: Fix race condition between signal delivery and wakeup file
|
- bpo-30038: Fix race condition between signal delivery and wakeup file
|
||||||
descriptor. Patch by Nathaniel Smith.
|
descriptor. Patch by Nathaniel Smith.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue