gh-118650: Exclude `_repr_*` methods from Enum's _sunder_ reservation (GH-118651)

This commit is contained in:
chrysn 2024-05-07 12:35:51 +02:00 committed by GitHub
parent 6cf70678e2
commit 1e428426c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View File

@ -365,7 +365,10 @@ class EnumDict(dict):
'_generate_next_value_', '_numeric_repr_', '_missing_', '_ignore_',
'_iter_member_', '_iter_member_by_value_', '_iter_member_by_def_',
'_add_alias_', '_add_value_alias_',
):
# While not in use internally, those are common for pretty
# printing and thus excluded from Enum's reservation of
# _sunder_ names
) and not key.startswith('_repr_'):
raise ValueError(
'_sunder_ names, such as %r, are reserved for future Enum use'
% (key, )

View File

@ -0,0 +1,2 @@
The ``enum`` module allows method named ``_repr_*`` to be defined on
``Enum`` types.