Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ruff] Check for shadowed map before suggesting fix (RUF058) #15790

Merged
merged 7 commits into from
Jan 28, 2025

Conversation

ntBre
Copy link
Contributor

@ntBre ntBre commented Jan 28, 2025

Summary

Fixes #15786 by not suggesting a fix if map doesn't have its builtin binding.

Test Plan

New test taken from the report in #15786.

@ntBre ntBre added bug Something isn't working fixes Related to suggested fixes for violations preview Related to preview mode features labels Jan 28, 2025
Copy link
Contributor

github-actions bot commented Jan 28, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Nice! While we're here, as an optional extra: this rule is lacking docs on why the fix is sometimes marked as unsafe (the reason looks like it's because it could destroy comments in some situations). We should probably add a ## Fix safety section to the docs that explains this (see #15584)

@ntBre
Copy link
Contributor Author

ntBre commented Jan 28, 2025

Good catch! I adapted the fix safety section from RUF055:

/// ## Fix safety
///
/// This rule's fix is marked as unsafe if the `starmap` or `zip` expressions contain comments that
/// would be deleted by applying the fix. Otherwise, the fix can be applied safely.

What about a ## Fix availability section? I only found one example of that in RUF052 with a quick grep. Maybe it's not usually in a separate section.

@AlexWaygood
Copy link
Member

AlexWaygood commented Jan 28, 2025

What about a ## Fix availability section? I only found one example of that in RUF052 with a quick grep. Maybe it's not usually in a separate section.

It's true that we don't document it as often currently, but I think it's nice to document that too when we can, for sure!

@ntBre
Copy link
Contributor Author

ntBre commented Jan 28, 2025

Sounds good! I added both new sections. I put safety first (pun somewhat intended), then availability, but happy to reverse it too.

@ntBre ntBre merged commit 786099a into main Jan 28, 2025
21 checks passed
@ntBre ntBre deleted the brent/shadow-map branch January 28, 2025 19:15
dcreager added a commit that referenced this pull request Jan 29, 2025
* main:
  [red-knot] Extend instance-attribute tests (#15808)
  Fix formatter warning message for `flake8-quotes` option (#15788)
  [`flake8-bugbear`] Exempt `NewType` calls where the original type is immutable (`B008`) (#15765)
  Add missing config docstrings (#15803)
  [`refurb`] Do not emit diagnostic when loop variables are used outside loop body (`FURB122`) (#15757)
  [`ruff`] Check for shadowed `map` before suggesting fix (`RUF058`) (#15790)
  [red-knot] Do not use explicit `knot_extensions.Unknown` declaration (#15787)
  Preserve quotes in generated byte strings (#15778)
  [minor] Simplify some `ExprStringLiteral` creation logic (#15775)
  Preserve quote style in generated code (#15726)
  Rename internal helper functions (#15771)
  [`airflow`] Extend airflow context parameter check for `BaseOperator.execute` (`AIR302`) (#15713)
  Implement tab autocomplete for `ruff config` (#15603)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixes Related to suggested fixes for violations preview Related to preview mode features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RUF058 fix does not check if map is shadowed
2 participants