From e51f55ca1b405c7214a82141529aca7e57e9f2af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?An=C5=BEe=20Pe=C4=8Dar?= Date: Wed, 21 Dec 2022 02:19:19 +0000 Subject: [PATCH 1/6] Clarify Enum.__format__() change of mixed-in types --- Doc/whatsnew/3.11.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 6f283f1d800202..736f7765a23149 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -676,10 +676,10 @@ enum * Changed :meth:`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. + to include the class name and member key in the output, not the member's value. 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'``. + instead of the member's value. * Added a new *boundary* class parameter to :class:`~enum.Flag` enums and the :class:`~enum.FlagBoundary` enum with its options, From 4ccc0fe0dc60e5399a9497d3229cc56cc4699c7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?An=C5=BEe=20Pe=C4=8Dar?= Date: Tue, 27 Dec 2022 14:47:29 +0000 Subject: [PATCH 2/6] Point users to StrEnum or IntEnum for old formatting behavior Co-authored-by: JosephSBoyle <48555120+JosephSBoyle@users.noreply.github.com> --- Doc/whatsnew/3.11.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 736f7765a23149..02f8664a33ff93 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -679,7 +679,7 @@ enum to include the class name and member key in the output, not the member's value. This matches the existing behavior of :meth:`enum.Enum.__str__`, returning e.g. ``'AnEnum.MEMBER'`` for an enum ``AnEnum(str, Enum)`` - instead of the member's value. + instead of the member's value. Those wishing to keep the old formatting behavior may wish to modify their enums with mixed-in types to inherit from one the appropriate :class:`StrEnum` or :class:`IntEnum` class. * Added a new *boundary* class parameter to :class:`~enum.Flag` enums and the :class:`~enum.FlagBoundary` enum with its options, From 0d265a05e047720c4124bbc517c14b8ddc5a84c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?An=C5=BEe=20Pe=C4=8Dar?= Date: Tue, 27 Dec 2022 14:56:36 +0000 Subject: [PATCH 3/6] Split into multiple ines --- Doc/whatsnew/3.11.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 02f8664a33ff93..ea9598a8afb04e 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -679,7 +679,9 @@ enum to include the class name and member key in the output, not the member's value. This matches the existing behavior of :meth:`enum.Enum.__str__`, returning e.g. ``'AnEnum.MEMBER'`` for an enum ``AnEnum(str, Enum)`` - instead of the member's value. Those wishing to keep the old formatting behavior may wish to modify their enums with mixed-in types to inherit from one the appropriate :class:`StrEnum` or :class:`IntEnum` class. + instead of the member's value. Those wishing to keep the old formatting behavior + may wish to modify their enums with mixed-in types to inherit from one the appropriate + :class:`StrEnum` or :class:`IntEnum` class. * Added a new *boundary* class parameter to :class:`~enum.Flag` enums and the :class:`~enum.FlagBoundary` enum with its options, From 5f30054cc28ad1dd770a90b9b07d47a25647bca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?An=C5=BEe=20Pe=C4=8Dar?= Date: Tue, 27 Dec 2022 14:57:13 +0000 Subject: [PATCH 4/6] Fix small typo --- Doc/whatsnew/3.11.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index ea9598a8afb04e..baea00119cb2ff 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -680,7 +680,7 @@ enum This matches the existing behavior of :meth:`enum.Enum.__str__`, returning e.g. ``'AnEnum.MEMBER'`` for an enum ``AnEnum(str, Enum)`` instead of the member's value. Those wishing to keep the old formatting behavior - may wish to modify their enums with mixed-in types to inherit from one the appropriate + may wish to modify their enums with mixed-in types to inherit from the appropriate :class:`StrEnum` or :class:`IntEnum` class. * Added a new *boundary* class parameter to :class:`~enum.Flag` enums From bee67cab2483c1d528cec97e30cea41afaa64eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?An=C5=BEe=20Pe=C4=8Dar?= Date: Wed, 22 Mar 2023 18:53:46 +0000 Subject: [PATCH 5/6] Address PR feedback --- Doc/whatsnew/3.11.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index baea00119cb2ff..81115176aa0221 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -676,10 +676,10 @@ enum * Changed :meth:`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 include the class name and member key in the output, not the member's value. + to show the class name and member name in the output, instead of the member's value. This matches the existing behavior of :meth:`enum.Enum.__str__`, - returning e.g. ``'AnEnum.MEMBER'`` for an enum ``AnEnum(str, Enum)`` - instead of the member's value. Those wishing to keep the old formatting behavior + returning e.g. ``'AnEnum.MEMBER'`` for an enum ``AnEnum(str, Enum)``. + Those wishing to keep the old formatting behavior may wish to modify their enums with mixed-in types to inherit from the appropriate :class:`StrEnum` or :class:`IntEnum` class. From 6aed4ca8b102df137e26452ddcfb1955a3b26d52 Mon Sep 17 00:00:00 2001 From: Ethan Furman Date: Mon, 17 Apr 2023 19:45:52 -0700 Subject: [PATCH 6/6] update prose --- Doc/whatsnew/3.11.rst | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 81115176aa0221..9de72a7c2c097d 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -667,21 +667,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__() ` - (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 show the class name and member name in the output, instead of the member's value. - This matches the existing behavior of :meth:`enum.Enum.__str__`, - returning e.g. ``'AnEnum.MEMBER'`` for an enum ``AnEnum(str, Enum)``. - Those wishing to keep the old formatting behavior - may wish to modify their enums with mixed-in types to inherit from the appropriate - :class:`StrEnum` or :class:`IntEnum` class. +* Changed :meth:`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,