[Python-checkins] bpo-38967: Improve the error msg for reserved _sunder_ names in enum (GH-18370)

Zackery Spytz webhook-mailer at python.org
Tue Sep 15 10:01:12 EDT 2020


https://github.com/python/cpython/commit/2ec67526a6ed3312f4fac22b527ca0ff161531b8
commit: 2ec67526a6ed3312f4fac22b527ca0ff161531b8
branch: master
author: Zackery Spytz <zspytz at gmail.com>
committer: GitHub <noreply at github.com>
date: 2020-09-13T13:27:51-07:00
summary:

bpo-38967: Improve the error msg for reserved _sunder_ names in enum (GH-18370)

files:
M Lib/enum.py
M Lib/test/test_enum.py

diff --git a/Lib/enum.py b/Lib/enum.py
index 49b552ba0ecf6..bc24f2ae2dfc0 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -76,7 +76,8 @@ def __setitem__(self, key, value):
                     '_order_', '_create_pseudo_member_',
                     '_generate_next_value_', '_missing_', '_ignore_',
                     ):
-                raise ValueError('_names_ are reserved for future Enum use')
+                raise ValueError(f'_sunder_ names, such as "{key}", are '
+                                  'reserved for future Enum use')
             if key == '_generate_next_value_':
                 # check if members already defined as auto()
                 if self._auto_called:
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index e7bad62406773..b18f3b38a6619 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -419,6 +419,11 @@ def red(self):
                 green = 2
                 blue = 3
 
+    def test_reserved__sunder_(self):
+        with self.assertRaisesRegex(ValueError, '_sunder_ names, such as '
+                                    '"_bad_", are reserved'):
+            class Bad(Enum):
+                _bad_ = 1
 
     def test_enum_with_value_name(self):
         class Huh(Enum):



More information about the Python-checkins mailing list