Skip to content

Commit 1e42842

Browse files
authored
gh-118650: Exclude _repr_* methods from Enum's _sunder_ reservation (GH-118651)
1 parent 6cf7067 commit 1e42842

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Lib/enum.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,10 @@ def __setitem__(self, key, value):
365365
'_generate_next_value_', '_numeric_repr_', '_missing_', '_ignore_',
366366
'_iter_member_', '_iter_member_by_value_', '_iter_member_by_def_',
367367
'_add_alias_', '_add_value_alias_',
368-
):
368+
# While not in use internally, those are common for pretty
369+
# printing and thus excluded from Enum's reservation of
370+
# _sunder_ names
371+
) and not key.startswith('_repr_'):
369372
raise ValueError(
370373
'_sunder_ names, such as %r, are reserved for future Enum use'
371374
% (key, )
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The ``enum`` module allows method named ``_repr_*`` to be defined on
2+
``Enum`` types.

0 commit comments

Comments
 (0)