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

Rule request: Detect dataclass() usage with Enum and its subclasses #15275

Closed
correctmost opened this issue Jan 5, 2025 · 2 comments · Fixed by #15299
Closed

Rule request: Detect dataclass() usage with Enum and its subclasses #15275

correctmost opened this issue Jan 5, 2025 · 2 comments · Fixed by #15299
Labels
accepted Ready for implementation rule Implementing or modifying a lint rule

Comments

@correctmost
Copy link

Motivation

There was a bug in archinstall because a dataclass decorator was incorrectly applied to an Enum:

@dataclass
class Audio(Enum):
    NoAudio = 'No audio server'
    Pipewire = 'pipewire'
    ...

The Python docs warn about such usage, but I am not aware of any linter that currently catches the error:

Adding dataclass() decorator to 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

Note: The docs mention that dataclass mixins can be used with enums, so there are some valid combinations of the constructs.

Related discussions

Documentation

Real world bugs

@InSyncWithFoo
Copy link
Contributor

There do seem to be quite a few bugs of this pattern.

@MichaReiser
Copy link
Member

Thanks, this makes sense to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants