8000 [3.11] gh-100458: Clarify Enum.__format__() change of mixed-in types … · python/cpython@723aacb · GitHub
[go: up one dir, main page]

Skip to content

Commit 723aacb

Browse files
miss-islingtonanze3dbJosephSBoyleethanfurman
authored
[3.11] gh-100458: Clarify Enum.__format__() change of mixed-in types in the whatsnew/3.11.rst (GH-100387) (GH-104060)
Co-authored-by: Anže Pečar <anze@pecar.me> Co-authored-by: JosephSBoyle <48555120+JosephSBoyle@users.noreply.github.com> Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
1 parent 0df7c3a commit 723aacb

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

Doc/whatsnew/3.11.rst

Lines changed: 5 additions & 13 deletions
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)
0