Skip to content

Commit e665563

Browse files
anze3dbJosephSBoyleethanfurman
authored
gh-100458: Clarify Enum.__format__() change of mixed-in types in the whatsnew/3.11.rst (GH-100387)
Co-authored-by: JosephSBoyle <[email protected]> Co-authored-by: Ethan Furman <[email protected]>
1 parent 3ed8c88 commit e665563

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
@@ -666,19 +666,11 @@ enum
666666
for :meth:`~object.__str__` and :meth:`~object.__format__`
667667
(used by :func:`str`, :func:`format` and :term:`f-string`\s).
668668

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

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

0 commit comments

Comments
 (0)