Skip to content

Commit 72d2d0f

Browse files
sobolevnEclips4ethanfurman
authored
gh-114803: Mention that @dataclass should not be applied on enums (GH-114891)
Co-authored-by: Kirill Podoprigora <[email protected]> Co-authored-by: Ethan Furman <[email protected]>
1 parent ab76d37 commit 72d2d0f

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Doc/howto/enum.rst

+18-1
Original file line numberDiff line numberDiff line change
@@ -497,13 +497,30 @@ the :meth:`~Enum.__repr__` omits the inherited class' name. For example::
497497
>>> Creature.DOG
498498
<Creature.DOG: size='medium', legs=4>
499499

500-
Use the :func:`!dataclass` argument ``repr=False``
500+
Use the :func:`~dataclasses.dataclass` argument ``repr=False``
501501
to use the standard :func:`repr`.
502502

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

507+
.. note::
508+
509+
Adding :func:`~dataclasses.dataclass` decorator to :class:`Enum`
510+
and its subclasses is not supported. It will not raise any errors,
511+
but it will produce very strange results at runtime, such as members
512+
being equal to each other::
513+
514+
>>> @dataclass # don't do this: it does not make any sense
515+
... class Color(Enum):
516+
... RED = 1
517+
... BLUE = 2
518+
...
519+
>>> Color.RED is Color.BLUE
520+
False
521+
>>> Color.RED == Color.BLUE # problem is here: they should not be equal
522+
True
523+
507524

508525
Pickling
509526
--------

0 commit comments

Comments
 (0)