bpo-37479: on Enum subclasses with mixins, __format__ uses overridden __str__ (GH-14545)

* bpo-37479: on Enum subclasses with mixins, __format__ uses overridden __str__
This commit is contained in:
thatneat 2019-07-04 11:28:37 -07:00 committed by Ethan Furman
parent b4e68960b9
commit 2f19e82fbe
5 changed files with 63 additions and 6 deletions

View file

@ -622,8 +622,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