Repository navigation
[ruff] Implicit class variable in dataclass (RUF045) - #14349
Conversation
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| RUF045 | 8 | 8 | 0 | 0 | 0 |
|
False positives found by ecosystem checks:
@dataclass
class FontFace:
family: str | None
emphasis: TextEmphasis | None
size_pt: int | None
color: DeviceGray | DeviceRGB | None
fill_color: DeviceGray | DeviceRGB | None
...
replace = dataclasses.replace
@dataclasses.dataclass(frozen=True)
class FuncFixtureInfo:
...
__slots__ = ("argnames", "initialnames", "names_closure", "name2fixturedefs")Special names can be exempted, but I'm not sure what to do about the first. |
|
I'm not saying we shouldn't do it, but requiring type annotations has been controversial in other instances; for example, there's a long thread for RUF012 that does something similar. @AlexWaygood I'd be interested on your take on this before I start reviewing the rule itself. |
641759f to
404fa94
Compare
dylwil3
left a comment
There was a problem hiding this comment.
Thank you!
Looking at the ecosystem results, it seems fairly common for users to define a private class variable in their dataclasses. So I've restricted the scope of the rule a little to exempt that.
Summary
Resolves #12877.
Test Plan
cargo nextest runandcargo insta test.