Skip to content

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

@correctmost

Description

@correctmost

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedReady for implementationruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions