Skip to content

Commit ff58045

Browse files
anze3dbJosephSBoyleethanfurman
authored andcommitted
pythongh-100458: Clarify Enum.__format__() change of mixed-in types in the whatsnew/3.11.rst (pythonGH-100387)
(cherry picked from commit e665563) Co-authored-by: Anže Pečar <[email protected]> Co-authored-by: JosephSBoyle <[email protected]> Co-authored-by: Ethan Furman <[email protected]>
1 parent 0df7c3a commit ff58045

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

Doc/whatsnew/3.11.rst

+5-13
Original file line numberDiff line numberDiff line change
@@ -668,19 +668,11 @@ enum
668668
for :meth:`~object.__str__` and :meth:`~object.__format__`
669669
(used by :func:`str`, :func:`format` and :term:`f-string`\s).
670670

671-
* Changed :class:`~enum.IntEnum`, :class:`~enum.IntFlag` and :class:`~enum.StrEnum`
672-
to now inherit from :class:`~enum.ReprEnum`,
673-
so their :func:`str` output now matches :func:`format`
674-
(both ``str(AnIntEnum.ONE)`` and ``format(AnIntEnum.ONE)`` return ``'1'``,
675-
whereas before ``str(AnIntEnum.ONE)`` returned ``'AnIntEnum.ONE'``.
676-
677-
* Changed :meth:`Enum.__format__() <enum.Enum.__format__>`
678-
(the default for :func:`format`, :meth:`str.format` and :term:`f-string`\s)
679-
of enums with mixed-in types (e.g. :class:`int`, :class:`str`)
680-
to also include the class name in the output, not just the member's key.
681-
This matches the existing behavior of :meth:`enum.Enum.__str__`,
682-
returning e.g. ``'AnEnum.MEMBER'`` for an enum ``AnEnum(str, Enum)``
683-
instead of just ``'MEMBER'``.
671+
* Changed :meth:`Enum.__format__() <enum.Enum.__format__>` (the default for
672+
:func:`format`, :meth:`str.format` and :term:`f-string`\s) to always produce
673+
the same result as :meth:`Enum.__str__()`: for enums inheriting from
674+
:class:`~enum.ReprEnum` it will be the member's value; for all other enums
675+
it will be the enum and member name (e.g. ``Color.RED``).
684676

685677
* Added a new *boundary* class parameter to :class:`~enum.Flag` enums
686678
and the :class:`~enum.FlagBoundary` enum with its options,

0 commit comments

Comments
 (0)