gh-114803: Mention that @dataclass
should not be applied on enums (GH-114891)
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru> Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
This commit is contained in:
parent
ab76d37948
commit
72d2d0f10d
@ -497,13 +497,30 @@ the :meth:`~Enum.__repr__` omits the inherited class' name. For example::
|
|||||||
>>> Creature.DOG
|
>>> Creature.DOG
|
||||||
<Creature.DOG: size='medium', legs=4>
|
<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`.
|
to use the standard :func:`repr`.
|
||||||
|
|
||||||
.. versionchanged:: 3.12
|
.. versionchanged:: 3.12
|
||||||
Only the dataclass fields are shown in the value area, not the dataclass'
|
Only the dataclass fields are shown in the value area, not the dataclass'
|
||||||
name.
|
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
|
Pickling
|
||||||
--------
|
--------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user