Skip to content

[pyflakes] Flag annotated variable redeclarations as F811 in preview mode#24244

Merged
dylwil3 merged 6 commits intoastral-sh:mainfrom
RenzoMXD:fix/f811-annotated-assignment-redefinition-preview
Mar 27, 2026
Merged

[pyflakes] Flag annotated variable redeclarations as F811 in preview mode#24244
dylwil3 merged 6 commits intoastral-sh:mainfrom
RenzoMXD:fix/f811-annotated-assignment-redefinition-preview

Conversation

@RenzoMXD
Copy link
Copy Markdown
Contributor

Summary

  • In preview mode, F811 now detects annotated variable redeclarations like bar: int = 1; bar: int = 2 as unused redefinitions
  • Plain reassignments (x = 1; x = 2) remain unflagged, as this is normal Python
  • Only triggers when both the original and the shadowing binding are annotated assignments with values
    • bar: int = 1; bar: int = 2 — flagged
    • bar = 1; bar = 2 — not flagged (plain reassignment)
    • bar = 1; bar: int = 2 — not flagged (mixed)
    • bar: int = 1; bar = 2 — not flagged (mixed)
    • bar: int = 1; print(bar); bar: int = 2 — not flagged (first is used)

Closes #23802

Test plan

  • Added F811_34.py test fixture covering all combinations (annotated/plain, used/unused)
  • All 35 existing F811 tests pass with no regressions
  • Full pyflakes suite passes (463 tests)

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 27, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+1 -0 violations, +0 -0 fixes in 1 projects; 55 projects unchanged)

prefecthq/prefect (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

+ src/prefect/client/schemas/responses.py:366:5: F811 Redefinition of unused `concurrency_options` from line 359: `concurrency_options` redefined here

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
F811 1 1 0 0 0

@MichaReiser MichaReiser assigned dylwil3 and unassigned amyreese Mar 27, 2026
@dylwil3
Copy link
Copy Markdown
Collaborator

dylwil3 commented Mar 27, 2026

Thanks for your interest in contributing to Ruff! Could you please take a look at the AI policy and make any necessary adjustments?

@MichaReiser MichaReiser requested review from dylwil3 and removed request for amyreese March 27, 2026 16:24
@RenzoMXD
Copy link
Copy Markdown
Contributor Author

@dylwil3 I checked every line one by one and all are good implemented. I used a BindingFlags flag instead of checking the statement directly. The preview gate is in the F811 checker rather than in redefines() because the semantic crate doesn't have access to linter settings. I updated the function in mod.rs. I think my PR is good but I expect any review from you.

@dylwil3 dylwil3 force-pushed the fix/f811-annotated-assignment-redefinition-preview branch from 3c9dcc1 to cc4f43c Compare March 27, 2026 17:58
@dylwil3
Copy link
Copy Markdown
Collaborator

dylwil3 commented Mar 27, 2026

Ok, thank you! I think we can get away with something a bit simpler without introducing a new flag. I pushed a different approach, we'll see if CI passes but it ought to be equivalent.

@dylwil3 dylwil3 added rule Implementing or modifying a lint rule preview Related to preview mode features labels Mar 27, 2026
@dylwil3 dylwil3 changed the title Flag annotated variable redeclarations as F811 in preview mode [pyflakes] Flag annotated variable redeclarations as F811 in preview mode Mar 27, 2026
Copy link
Copy Markdown
Collaborator

@dylwil3 dylwil3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just need some documentation.

@RenzoMXD RenzoMXD requested a review from dylwil3 March 27, 2026 18:41
@dylwil3 dylwil3 merged commit f283ddc into astral-sh:main Mar 27, 2026
42 checks passed
carljm added a commit that referenced this pull request Mar 31, 2026
* main: (40 commits)
  [ty] resolve union-likes in emitting union attribute errors (#24263)
  [ty] Improve support for `Callable` type context (#23888)
  [ty] Propagate type context through `await` expressions (#24256)
  [`pyflakes`] Flag annotated variable redeclarations as `F811` in preview mode (#24244)
  [ty] Preserve `Divergent` when materializing recursive aliases (#24245)
  Fix W391 fixes for consecutive empty notebook cells (#24236)
  [flake8-bugbear] Clarify RUF071 fix safety for non-path string comparisons (#24149)
  [ty] Ban type qualifiers in PEP-695 type aliases (#24242)
  [ty] Include keyword-prefixed symbols in completions for attributes (#24232)
  [ty] Add tests for TypedDict method overloads on unions (#24230)
  [ty] report unused bindings as unnecessary hint diagnostics (#23305)
  Remove unused `non_root` variable (#24238)
  Extend F507 to flag %-format strings with zero placeholders (#24215)
  [`flake8-simplify`] Suppress `SIM105` for `except*` before Python 3.12 (#23869)
  Ignore pre-initialization references in SIM113 (#24235)
  Parenthesize expression in RUF050 fix (#24234)
  Publish playgrounds using the `release-playground` environment (#24223)
  [ty] Fix instance-attribute lookup in methods of protocol classes (#24213)
  [ty] Used shared expression cache during generic call inference (#24219)
  [ty] make `Type::BoundMethod` include instances of same-named methods bound to a subclass (#24039)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview Related to preview mode features rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

redefined-while-unused (F811) - false negative on variable redeclaration

3 participants