From 2ec67526a6ed3312f4fac22b527ca0ff161531b8 Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Sun, 13 Sep 2020 14:27:51 -0600 Subject: [PATCH] bpo-38967: Improve the error msg for reserved _sunder_ names in enum (GH-18370) --- Lib/enum.py | 3 ++- Lib/test/test_enum.py | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Lib/enum.py b/Lib/enum.py index 49b552ba0ec..bc24f2ae2df 100644 --- a/Lib/enum.py +++ b/Lib/enum.py @@ -76,7 +76,8 @@ class _EnumDict(dict): '_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 e7bad624067..b18f3b38a66 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -419,6 +419,11 @@ class TestEnum(unittest.TestCase): 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):