diff options
author | 2020-09-15 17:16:36 -0700 | |
---|---|---|
committer | 2020-09-15 17:16:36 -0700 | |
commit | 929112ef81ccef20d3aef25c8a1142059ee941da (patch) | |
tree | 6cf804656766ed3b21d5ab765245b13fa8ef127a /Lib/enum.py | |
parent | bpo-39587: Enum - use correct mixed-in data type (GH-22263) (diff) | |
download | cpython-929112ef81ccef20d3aef25c8a1142059ee941da.tar.gz cpython-929112ef81ccef20d3aef25c8a1142059ee941da.tar.bz2 cpython-929112ef81ccef20d3aef25c8a1142059ee941da.zip |
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
(cherry picked from commit 22415ad62555d79bd583b4a7d6a96006624a8277)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Diffstat (limited to 'Lib/enum.py')
-rw-r--r-- | Lib/enum.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/enum.py b/Lib/enum.py index dfde75048b0..c892d738f8b 100644 --- a/Lib/enum.py +++ b/Lib/enum.py @@ -249,7 +249,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) |