8000 gh-94943: [Enum] improve repr() when inheriting from a dataclass by ethanfurman · Pull Request #99740 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-94943: [Enum] improve repr() when inheriting from a dataclass #99740

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

Merged
merged 4 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
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
Prev Previous commit
Apply suggestions from code review
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
  • Loading branch information
ethanfurman and CAM-Gerlach authored Nov 24, 2022
commit a8ead294be6c4e24706940bb6fb9809a2f927213
9 changes: 5 additions & 4 deletions Doc/howto/enum.rst
8000
Original file line number Diff line number Diff line change
Expand Up @@ -459,13 +459,13 @@ sense to allow sharing some common behavior between a group of enumerations.
(See `OrderedEnum`_ for an example.)


.. _dataclass_support:
.. _enum-dataclass-support:

Dataclass support
-----------------

When inheriting from a :func:`dataclass` the :func:`repr` omits the inherited
class' name. For example::
When inheriting from a :class:`~dataclasses.dataclass`,
the :meth:`~Enum.__repr__` omits the inherited class' name. For example::

>>> @dataclass
... class CreatureDataMixin:
Expand All @@ -480,7 +480,8 @@ class' name. For example::
>>> Creature.DOG
<Creature.DOG: size='medium', legs=4>

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


Pickling
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ Data Types
Using :class:`auto` with :class:`Enum` results in integers of increasing value,
starting with ``1``.

.. versionchanged:: 3.12 add :ref:`dataclass_support`
.. versionchanged:: 3.12 Added :ref:`enum-dataclass-support`


.. class:: IntEnum
Expand Down
1 change: 0 additions & 1 deletion Lib/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,6 @@ def _dataclass_repr(self):
if dcf[k].repr
)


def global_enum_repr(self):
"""
use module.enum_name instead of class.enum_name
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
When inheriting from a dataclass, only show the field names in the value section of the member repr(), and not the dataclass' class name.
Add :ref:`enum-dataclass-support` to the
:class:`~enum.Enum` :meth:`~enum.Enum.__repr__`.
When inheriting from a :class:`~dataclasses.dataclass`,
only show the field names in the value section of the member :func:`repr`,
and not the dataclass' class name.
0