Skip to content
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

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

Closed
ethanfurman opened this issue Jul 18, 2022 · 0 comments
Closed

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

ethanfurman opened this issue Jul 18, 2022 · 0 comments
Assignees
Labels
3.12 bugs and security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@ethanfurman
Copy link
Member

ethanfurman commented Jul 18, 2022

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

@ethanfurman ethanfurman added the type-feature A feature request or enhancement label Jul 18, 2022
@ethanfurman ethanfurman changed the title Enhance dataclass repr() when combined with Enum [Enum] Enhance repr() when decorated with dataclass Jul 18, 2022
@ethanfurman ethanfurman changed the title [Enum] Enhance repr() when decorated with dataclass [Enum] Enhance repr() when inheriting from dataclass Jul 18, 2022
@ethanfurman ethanfurman self-assigned this Nov 21, 2022
@CAM-Gerlach CAM-Gerlach added stdlib Python modules in the Lib dir 3.12 bugs and security fixes labels Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants