diff options
| author | Dong-hee Na <donghee.na92@gmail.com> | 2017-06-25 01:12:20 +0900 |
|---|---|---|
| committer | ethanfurman <ethan@stoneleaf.us> | 2017-06-24 09:12:20 -0700 |
| commit | 504b95047a8ada06ab630abce55ac2f85566ca37 (patch) | |
| tree | 125a8999ed6afd64b792a5cd390c5b793d5ae992 | |
| parent | 0e1f9e8d3ea82262cbb9a403b70a884da5e6a6ac (diff) | |
| download | cpython-git-504b95047a8ada06ab630abce55ac2f85566ca37.tar.gz | |
[3.6] bpo-30616: Functional API of enum allows to create empty enums. (#2304) (#2324)
| -rw-r--r-- | Lib/enum.py | 2 | ||||
| -rw-r--r-- | Lib/test/test_enum.py | 20 | ||||
| -rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 24 insertions, 1 deletions
diff --git a/Lib/enum.py b/Lib/enum.py index 056400d04c..73dd613887 100644 --- a/Lib/enum.py +++ b/Lib/enum.py @@ -381,7 +381,7 @@ class EnumMeta(type): # special processing needed for names? if isinstance(names, str): 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, [] last_values = [] for count, name in enumerate(original_names): diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index 13a89fc2db..eaea8ee3ab 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -2291,6 +2291,26 @@ class TestIntFlag(unittest.TestCase): 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): Perm = self.Perm R, W, X = Perm @@ -89,6 +89,9 @@ Core and Builtins Library ------- +- 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 descriptor. Patch by Nathaniel Smith. |
