[New-bugs-announce] [issue43945] [Enum] standardize format() behavior
Ethan Furman
report at bugs.python.org
Mon Apr 26 19:04:32 EDT 2021
New submission from Ethan Furman <ethan at stoneleaf.us>:
Currently, an enum with a mixed-in data type, such as IntEnum, will use that data type's `__format__` -- unless the user provides their own `__str__`, in which case the `str()` of the enum member will be used in the `format()` call.
This behavior will be deprecated in 3.10, and in 3.12 the default `__format__` will use the default `__str__`, which is the standard behavior for Python objects
For those that were relying on, for example,
class Color(IntEnum):
RED = 1
f'{Color.RED}' # -> '2'
They will need to add ":d" to ensure the integer output:
f'{Color.RED:d}'
This change does work now.
----------
assignee: ethan.furman
messages: 391995
nosy: ethan.furman
priority: normal
severity: normal
stage: needs patch
status: open
title: [Enum] standardize format() behavior
type: behavior
versions: Python 3.10, Python 3.11
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43945>
_______________________________________
More information about the New-bugs-announce
mailing list