[Python-checkins] [3.11] gh-100458: Clarify Enum.__format__() change of mixed-in types in the whatsnew/3.11.rst (GH-100387) (GH-104060)
ethanfurman
webhook-mailer at python.org
Mon May 1 16:06:17 EDT 2023
https://github.com/python/cpython/commit/723aacb7d5cf03b36c053c1f27fcfb3efdc9ae45
commit: 723aacb7d5cf03b36c053c1f27fcfb3efdc9ae45
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: ethanfurman <ethan at stoneleaf.us>
date: 2023-05-01T13:06:09-07:00
summary:
[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 at pecar.me>
Co-authored-by: JosephSBoyle <48555120+JosephSBoyle at users.noreply.github.com>
Co-authored-by: Ethan Furman <ethan at stoneleaf.us>
files:
M Doc/whatsnew/3.11.rst
diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst
index 75963175042d..378315b36c6e 100644
--- a/Doc/whatsnew/3.11.rst
+++ b/Doc/whatsnew/3.11.rst
@@ -668,19 +668,11 @@ enum
for :meth:`~object.__str__` and :meth:`~object.__format__`
(used by :func:`str`, :func:`format` and :term:`f-string`\s).
-* Changed :class:`~enum.IntEnum`, :class:`~enum.IntFlag` and :class:`~enum.StrEnum`
- to now inherit from :class:`~enum.ReprEnum`,
- so their :func:`str` output now matches :func:`format`
- (both ``str(AnIntEnum.ONE)`` and ``format(AnIntEnum.ONE)`` return ``'1'``,
- whereas before ``str(AnIntEnum.ONE)`` returned ``'AnIntEnum.ONE'``.
-
-* Changed :meth:`Enum.__format__() <enum.Enum.__format__>`
- (the default for :func:`format`, :meth:`str.format` and :term:`f-string`\s)
- of enums with mixed-in types (e.g. :class:`int`, :class:`str`)
- to also include the class name in the output, not just the member's key.
- This matches the existing behavior of :meth:`enum.Enum.__str__`,
- returning e.g. ``'AnEnum.MEMBER'`` for an enum ``AnEnum(str, Enum)``
- instead of just ``'MEMBER'``.
+* Changed :meth:`Enum.__format__() <enum.Enum.__format__>` (the default for
+ :func:`format`, :meth:`str.format` and :term:`f-string`\s) to always produce
+ the same result as :meth:`Enum.__str__()`: for enums inheriting from
+ :class:`~enum.ReprEnum` it will be the member's value; for all other enums
+ it will be the enum and member name (e.g. ``Color.RED``).
* Added a new *boundary* class parameter to :class:`~enum.Flag` enums
and the :class:`~enum.FlagBoundary` enum with its options,
More information about the Python-checkins
mailing list