Skip to content

Create rule to prefer class based syntax over functional syntax for Enums #12417

@mezuzza

Description

@mezuzza

There are a number of cases where you have a choice between class based syntax and functional syntax. The specific case I'm considering is Enum - though I do vaguely recall that there are other cases.

For example, you defined an enum using either of these methods:

class Color(Enum):
    RED = auto()
    YELLOW = auto()
    GREEN = auto()
Color = Enum(
    "Color",
    [
        "RED",
        "YELLOW",
        "GREEN",
    ],
)

What you prefer is a matter of taste (though honestly, if you prefer functional style, you're a little crazy) - however, I'd like to make sure we prefer the former throughout our codebase at work. This lint could obviously warn in either direction.

I'm a little surprised this suggestion didn't exist before tbh, so feel free to point me to the old ticket if it exists. I did search for "enums" and "functional" to try to find this issue, but I couldn't find it (I also tried a few others queries, but you get the idea).

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-decisionAwaiting a decision from a maintainerruleImplementing 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