Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitff58045

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 commite665563)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 parent0df7c3a commitff58045

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)

[8]ページ先頭

©2009-2026 Movatter.jp