Skip to content

PIE794: Detect duplicated declared class fields#22717

Merged
MichaReiser merged 1 commit intomainfrom
micha/fix-PIE794-annotated-assignments
Jan 19, 2026
Merged

PIE794: Detect duplicated declared class fields#22717
MichaReiser merged 1 commit intomainfrom
micha/fix-PIE794-annotated-assignments

Conversation

@MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Jan 19, 2026

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.

@MichaReiser MichaReiser added bug Something isn't working rule Implementing or modifying a lint rule labels Jan 19, 2026
@astral-sh-bot
Copy link

astral-sh-bot bot commented Jan 19, 2026

ruff-ecosystem results

Linter (stable)

ℹ️ 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)

+ 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

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

@MichaReiser
Copy link
Member Author

@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 reflex project look legit to you (does it define a class and field level fill attribute?)

@AlexWaygood
Copy link
Member

The reflex hits look like true positives to me! They're basically doing this:

class Foo:
    x: int = 0
    # 10 lines later...
    x: int

and there's no reason to do that instead of just:

class Foo:
    x: int = 0

We 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"

@MichaReiser
Copy link
Member Author

We 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):

I thought about that too but this seems like a separate change to the rule

@MichaReiser MichaReiser merged commit 2bc4756 into main Jan 19, 2026
43 checks passed
@MichaReiser MichaReiser deleted the micha/fix-PIE794-annotated-assignments branch January 19, 2026 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PIE794 Duplicate class field not marked as duplicate

3 participants