Skip to content

[Enum] Enhance repr() when inheriting from dataclass #94943

Closed

Description

@ethanfurman

In 3.10 and prior, a combined dataclass/enum such as

from dataclasses import dataclass

from enum import Enum

@dataclass(frozen=True)
class CreatureDataMixin:
    size: str
    legs: int

class Creature(CreatureDataMixin, Enum):
    BEETLE = ('small', 6)
    DOG = ('medium', 4)

had a repr() similar to

Creature(size='medium', legs=4)

In 3.11 that has been corrected to:

<Creature.DOG: CreatureDataMixin(size='medium', legs=4)>

Ideally, that would be:

<Creature.DOG: size='medium', legs=4>

Linked PRs

Activity

  1. changed the title [-]Enhance dataclass repr() when combined with Enum[/-] [+][Enum] Enhance repr() when decorated with dataclass[/+] on Jul 18, 2022
  2. changed the title [-][Enum] Enhance repr() when decorated with dataclass[/-] [+][Enum] Enhance repr() when inheriting from dataclass[/+] on Jul 18, 2022
  3. self-assigned this
    on Nov 21, 2022
  4. added
    stdlibStandard Library Python modules in the Lib/ directory
    3.12only security fixes
    on Nov 24, 2022
  5. added a commit that references this issue on Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.12only security fixesstdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions