https://github.com/python/cpython/commit/1e428426c836b9a434810a6b99f70454d3a9611e
commit: 1e428426c836b9a434810a6b99f70454d3a9611e
branch: main
author: chrysn <[email protected]>
committer: encukou <[email protected]>
date: 2024-05-07T12:35:51+02:00
summary:

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

files:
A Misc/NEWS.d/next/Library/2024-05-06-16-52-40.gh-issue-118650.qKz5lp.rst
M Lib/enum.py

diff --git a/Lib/enum.py b/Lib/enum.py
index 5485306c18843b..c36fc75a24a239 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -365,7 +365,10 @@ def __setitem__(self, key, value):
                     '_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, )
diff --git 
a/Misc/NEWS.d/next/Library/2024-05-06-16-52-40.gh-issue-118650.qKz5lp.rst 
b/Misc/NEWS.d/next/Library/2024-05-06-16-52-40.gh-issue-118650.qKz5lp.rst
new file mode 100644
index 00000000000000..85575ea9ce8725
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-05-06-16-52-40.gh-issue-118650.qKz5lp.rst
@@ -0,0 +1,2 @@
+The ``enum`` module allows method named ``_repr_*`` to be defined on
+``Enum`` types.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to