]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.6] bpo-30616: Functional API of enum allows to create empty enums. (#2304) (#2324)
authorDong-hee Na <donghee.na92@gmail.com>
Sat, 24 Jun 2017 16:12:20 +0000 (01:12 +0900)
committerethanfurman <ethan@stoneleaf.us>
Sat, 24 Jun 2017 16:12:20 +0000 (09:12 -0700)
Lib/enum.py
Lib/test/test_enum.py
Misc/NEWS

index 056400d04c94a1d2c98c6880840ecf13bf991b41..73dd613887d22b55d15bf7be18a927db446506b2 100644 (file)
@@ -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):
index 13a89fc2db6390e243af204b9dc680fe17cc6580..eaea8ee3abdfc92ce4e15965344cc98f572ee93d 100644 (file)
@@ -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
index 371dcf8ff0d0ac9bba5c2ab52d96aee5d36da7a8..3f5798268fa81c2a8ac69bc58a26baecc069efc1 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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.