Generated __init__, __eq__ and __repr__ replace those of an Enum subclass
What it finds
@dataclass class Color(Enum):: an enum's members are made by the enum machinery from the class body, and the __init__, __eq__ and __repr__ that dataclass writes replace the enum's own, so members compare and print differently from what either class promises and some definitions fail. Since Python 3.12 the documentation says not to combine them.
From the rule's source, enum_with_generated_methods.rs.
from dataclasses import dataclassfrom enum import Enum, IntEnum @dataclassclass Color(Enum):tx0 reports: this class derives from enum.Enum and is also a dataclass RED = 1 @dataclass(frozen=True)class Level(IntEnum):tx0 reports: derives from enum.IntEnum LOW = 1 class Shade(Enum): DARK = 1 @dataclassclass Pixel: color: Color Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/python:enum-with-generated-methods" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
# tx0: ignore[tx0/python:enum-with-generated-methods] reason="..."tx0 explain tx0/python:enum-with-generated-methods shows the same in the terminal. Found a false positive? Report it.