summaryrefslogtreecommitdiffstats
path: root/Lib/enum.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2020-09-13 20:47:43 (GMT)
committerGitHub <noreply@github.com>2020-09-13 20:47:43 (GMT)
commit38c8d3930eb872258a82339bcba3bce1d0e3ac2c (patch)
treecf9087f277d04c2ebf320a55f4f41cb4f7c51e2a /Lib/enum.py
parentbf50b0e80a8a0d651af2f953b662eeadd27c7c93 (diff)
downloadcpython-38c8d3930eb872258a82339bcba3bce1d0e3ac2c.zip
cpython-38c8d3930eb872258a82339bcba3bce1d0e3ac2c.tar.gz
cpython-38c8d3930eb872258a82339bcba3bce1d0e3ac2c.tar.bz2
[3.8] bpo-37479: Enum - use correct __format__ (GH-14545)
* bpo-37479: on Enum subclasses with mixins, __format__ uses overridden __str__. (cherry picked from commit 2f19e82fbe98ce86bcd98a176328af2808b678e8) Co-authored-by: thatneat <thatneat@users.noreply.github.com>
Diffstat (limited to 'Lib/enum.py')
-rw-r--r--Lib/enum.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/Lib/enum.py b/Lib/enum.py
index 14cc00e..16033b1 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -633,8 +633,9 @@ class Enum(metaclass=EnumMeta):
# we can get strange results with the Enum name showing up instead of
# the value
- # pure Enum branch
- if self._member_type_ is object:
+ # pure Enum branch, or branch with __str__ explicitly overridden
+ str_overridden = type(self).__str__ != Enum.__str__
+ if self._member_type_ is object or str_overridden:
cls = str
val = str(self)
# mix-in branch