
On 2021-04-20 20:42, Ethan Furman wrote:
On 4/20/21 12:01 PM, Guido van Rossum wrote:
On Tue, Apr 20, 2021 at 11:12 AM Ethan Furman wrote:
Moving forward, I'm not sure having format() and str() ever be different is a good idea, especially since users who need, for example, Color.RED to be '1' can simply add a `__str__ = int.__str__` to their own custom base IntEnum class and be good to go. If we deprecate the current behavior now we could change it in 3.12.
Thoughts?
So to be clear, that one user wants f"{Color.RED}" to return "1" and not " Color.RED" (or something like that). And you want f"{Color.RED}" and str(Color.RED) to return the same value. Then together that means that str(Color.RED) must also return "1".
Did I get that right? And are you happy with that outcome?
Almost right. They should both return `Color.RED`. Any users who want something different will need to do some work on their end:
class MyIntEnum(IntEnum): def __format__ = int.__format__
class Color(MyIntEnum): RED = 1
format(Color.RED) # '1'
The deprecation period will give that user, and others like them, time to add their own Enum base classes with the `__format__` method they desire.
Couldn't the format accept 'd' if they want an int, i.e. f"{Color.RED:d}"?