bpo-38967: Improve the error msg for reserved _sunder_ names in enum (GH-18370)
This commit is contained in:
parent
b48389d950
commit
2ec67526a6
|
@ -76,7 +76,8 @@ class _EnumDict(dict):
|
||||||
'_order_', '_create_pseudo_member_',
|
'_order_', '_create_pseudo_member_',
|
||||||
'_generate_next_value_', '_missing_', '_ignore_',
|
'_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_':
|
if key == '_generate_next_value_':
|
||||||
# check if members already defined as auto()
|
# check if members already defined as auto()
|
||||||
if self._auto_called:
|
if self._auto_called:
|
||||||
|
|
|
@ -419,6 +419,11 @@ class TestEnum(unittest.TestCase):
|
||||||
green = 2
|
green = 2
|
||||||
blue = 3
|
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):
|
def test_enum_with_value_name(self):
|
||||||
class Huh(Enum):
|
class Huh(Enum):
|
||||||
|
|
Loading…
Reference in New Issue