[issue18738] String formatting (% and str.format) issues with Enum

Eli Bendersky report at bugs.python.org
Thu Aug 15 23:46:50 CEST 2013


Eli Bendersky added the comment:

The whole point of IntEnum and replacing stdlib constants with it was friendly str & repr out of the box. This means that "just printing out" an enum member should have a nice string representation. And "just printing out" means:

print(member)
"%s" % member
"{}".format(member)

!s/!r are quite esoteric - IntEnum should behave in the nicest way possible out of the box.

Let's just rig IntEnum's __format__ to do the right thing and not worry about Enum itself. I hope that mixin-with-Enum cases are rare (and most are IntEnum anyway), and in such rare cases users are free to lift the implementation from IntEnum.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18738>
_______________________________________


More information about the Python-bugs-list mailing list