Skip to content

Commit

Permalink
pythongh-114803: Mention that @dataclass should not be applied on e…
Browse files Browse the repository at this point in the history
…nums (pythonGH-114891)

Co-authored-by: Kirill Podoprigora <[email protected]>
Co-authored-by: Ethan Furman <[email protected]>
  • Loading branch information
3 people authored Feb 3, 2024
1 parent ab76d37 commit 72d2d0f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Doc/howto/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -497,13 +497,30 @@ 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 :class:`Enum`
and its subclasses is not supported. It will not raise any errors,
but it will produce very strange results at runtime, such as members
being equal to each other::

>>> @dataclass # don't do this: it does not make any sense
... class Color(Enum):
... RED = 1
... BLUE = 2
...
>>> Color.RED is Color.BLUE
False
>>> Color.RED == Color.BLUE # problem is here: they should not be equal
True


Pickling
--------
Expand Down

0 comments on commit 72d2d0f

Please sign in to comment.