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

This commit is contained in:
Zackery Spytz 2020-09-13 14:27:51 -06:00 committed by GitHub
parent b48389d950
commit 2ec67526a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -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:

View File

@ -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):