Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-114803: Mention that @dataclass should not be applied on enums #114891

Merged
merged 5 commits into from
Feb 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Doc/howto/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -497,13 +497,23 @@ the :meth:`~Enum.__repr__` omits the inherited class' name. For example::
>>> Creature.DOG
<Creature.DOG: size='medium', legs=4>

Use the :func:`!dataclass` argument ``repr=False``
Use the :func:`~dataclasses.dataclass` argument ``repr=False``
to use the standard :func:`repr`.

.. versionchanged:: 3.12
Only the dataclass fields are shown in the value area, not the dataclass'
name.

.. note::

Adding :func:`~dataclasses.dataclass` decorator to :type:`Enum`
sobolevn marked this conversation as resolved.
Show resolved Hide resolved
and its subclasses is not supported. It will not raise any errors,
but it will produce very strange results at runtime::
sobolevn marked this conversation as resolved.
Show resolved Hide resolved

@dataclass # don't do this: it does not make any sense
class Colors(Enum):
red = 'red'
ethanfurman marked this conversation as resolved.
Show resolved Hide resolved


Pickling
--------
Expand Down
Loading