summaryrefslogtreecommitdiffstats
path: root/Doc/howto
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2023-04-13 15:31:03 (GMT)
committerGitHub <noreply@github.com>2023-04-13 15:31:03 (GMT)
commita6f95941a3d686707fb38e0f37758e666f25e180 (patch)
tree0ea29dae5df68a1d67ec01e648659c79f9ff15e6 /Doc/howto
parent2194071540313e2bbdc7214d77453b9ce3034a5c (diff)
downloadcpython-a6f95941a3d686707fb38e0f37758e666f25e180.zip
cpython-a6f95941a3d686707fb38e0f37758e666f25e180.tar.gz
cpython-a6f95941a3d686707fb38e0f37758e666f25e180.tar.bz2
gh-103479: [Enum] require __new__ to be considered a data type (GH-103495)
a mixin must either have a __new__ method, or be a dataclass, to be interpreted as a data-type
Diffstat (limited to 'Doc/howto')
-rw-r--r--Doc/howto/enum.rst8
1 files changed, 5 insertions, 3 deletions
diff --git a/Doc/howto/enum.rst b/Doc/howto/enum.rst
index 9390fad..56391a0 100644
--- a/Doc/howto/enum.rst
+++ b/Doc/howto/enum.rst
@@ -865,17 +865,19 @@ Some rules:
4. When another data type is mixed in, the :attr:`value` attribute is *not the
same* as the enum member itself, although it is equivalent and will compare
equal.
-5. %-style formatting: ``%s`` and ``%r`` call the :class:`Enum` class's
+5. A ``data type`` is a mixin that defines :meth:`__new__`, or a
+ :class:`~dataclasses.dataclass`
+6. %-style formatting: ``%s`` and ``%r`` call the :class:`Enum` class's
:meth:`__str__` and :meth:`__repr__` respectively; other codes (such as
``%i`` or ``%h`` for IntEnum) treat the enum member as its mixed-in type.
-6. :ref:`Formatted string literals <f-strings>`, :meth:`str.format`,
+7. :ref:`Formatted string literals <f-strings>`, :meth:`str.format`,
and :func:`format` will use the enum's :meth:`__str__` method.
.. note::
Because :class:`IntEnum`, :class:`IntFlag`, and :class:`StrEnum` are
designed to be drop-in replacements for existing constants, their
- :meth:`__str__` method has been reset to their data types
+ :meth:`__str__` method has been reset to their data types'
:meth:`__str__` method.
When to use :meth:`__new__` vs. :meth:`__init__`