summaryrefslogtreecommitdiffstats
path: root/Lib/enum.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2020-09-15 23:28:25 (GMT)
committerGitHub <noreply@github.com>2020-09-15 23:28:25 (GMT)
commit22415ad62555d79bd583b4a7d6a96006624a8277 (patch)
treed85eb13c71814c8169749ef10581bb98d9b678b5 /Lib/enum.py
parent47f6ec4c09a138e9049fd245ca312842ff50ce42 (diff)
downloadcpython-22415ad62555d79bd583b4a7d6a96006624a8277.zip
cpython-22415ad62555d79bd583b4a7d6a96006624a8277.tar.gz
cpython-22415ad62555d79bd583b4a7d6a96006624a8277.tar.bz2
bpo-41789: honor object overrides in Enum classes (GH-22250)
EnumMeta double-checks that `__repr__`, `__str__`, `__format__`, and `__reduce_ex__` are not the same as `object`'s, and replaces them if they are -- even if that replacement was intentionally done in the Enum being constructed. This patch fixes that. Automerge-Triggered-By: @ethanfurman
Diffstat (limited to 'Lib/enum.py')
-rw-r--r--Lib/enum.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/enum.py b/Lib/enum.py
index 5e0088e..e72d306 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -250,7 +250,11 @@ class EnumMeta(type):
# double check that repr and friends are not the mixin's or various
# things break (such as pickle)
+ # however, if the method is defined in the Enum itself, don't replace
+ # it
for name in ('__repr__', '__str__', '__format__', '__reduce_ex__'):
+ if name in classdict:
+ continue
class_method = getattr(enum_class, name)
obj_method = getattr(member_type, name, None)
enum_method = getattr(first_enum, name, None)