PIE794: Detect duplicated declared class fields#22717
Conversation
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| PIE794 | 2 | 2 | 0 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+2 -0 violations, +0 -0 fixes in 1 projects; 54 projects unchanged)
reflex-dev/reflex (+2 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --no-fix --output-format concise --preview
+ reflex/components/recharts/cartesian.py:245:5: PIE794 Class field `fill` is defined multiple times + reflex/components/recharts/cartesian.py:248:5: PIE794 Class field `stroke` is defined multiple times
Changes by rule (1 rules affected)
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| PIE794 | 2 | 2 | 0 | 0 | 0 |
|
@AlexWaygood I always get confused about the trillion different ways on how you can define field and class level attributes in Python. Does the usage in the |
|
The reflex hits look like true positives to me! They're basically doing this: class Foo:
x: int = 0
# 10 lines later...
x: intand there's no reason to do that instead of just: class Foo:
x: int = 0We might want to be careful about redeclarations to a different type, though? ty supports these, although no other type checker does (at least, not by default): class Foo:
x: int = 0
x: str = "foo" |
I thought about that too but this seems like a separate change to the rule |
Summary
Fixes #22683
The rule skipped annotated assignments without a value. This seems an unintentional change that was introduced in #8634. This PR re-enables detecting duplicated class fields where a later declaration is an annotated assignment without a value.
We might have to preview gate this change if there are many ecosystem hits. Although I doubt that, given that this is unlikely very common.
Test Plan
Added regression test.