Skip to content

[flake8-gettext] Resolve qualified names and built-in bindings (INT001, INT002, INT003) - #19045

Merged
ntBre merged 6 commits into
astral-sh:mainfrom
robsdedude:fix/19028-flake8-gettext-false-negative
Oct 20, 2025
Merged

ntBre merged 6 commits into
astral-sh:mainfrom
robsdedude:fix/19028-flake8-gettext-false-negative

Conversation

@robsdedude

@robsdedude robsdedude commented Jun 30, 2025 •

Copy link
Copy Markdown
Contributor

Summary

Make rules INT001, INT002, and INT003 also

  • trigger on qualified names when we're sure the calls are calls to the gettext module. For example
    from gettext import gettext as foo
    
    foo(f"{'bar'}")  # very certain that this is a call to a real `gettext` function => worth linting
  • trigger on builtins bindings
    from builtins, gettext
    
    gettext.install("...")  # binds `gettext.gettext` to `builtins._`
    builtins.__dict__["_"] = ...  # also a common pattern
    
    _(f"{'bar'}")  # should therefore also be linted

Fixes: #19028

Test Plan

Tests have been added to all three rules.

@github-actions

github-actions Bot commented Jun 30, 2025 •

Copy link
Copy Markdown
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@robsdedude
robsdedude force-pushed the fix/19028-flake8-gettext-false-negative branch from 6a267e8 to 911adc3 Compare June 30, 2025 21:57
@robsdedude robsdedude changed the title [flake8_gettext]: Make INTxxx rules also trigger on aliased imports [flake8_gettext]: Expand scope of INTxxx rules Jun 30, 2025
@robsdedude robsdedude changed the title [flake8_gettext]: Expand scope of INTxxx rules [flake8_gettext] Expand scope of INTxxx rules Jun 30, 2025
@codspeed

codspeed Bot commented Jun 30, 2025 •

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #19045 will not alter performance

Comparing robsdedude:fix/19028-flake8-gettext-false-negative (da2ec00) with main (590ce9d)

Summary

✅ 30 untouched
⏩ 22 skipped1

Footnotes

  1. 22 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@robsdedude
robsdedude force-pushed the fix/19028-flake8-gettext-false-negative branch from 911adc3 to f6fdd46 Compare June 30, 2025 22:11
@robsdedude
robsdedude force-pushed the fix/19028-flake8-gettext-false-negative branch from f6fdd46 to eec7743 Compare June 30, 2025 22:13
@robsdedude
robsdedude marked this pull request as ready for review July 1, 2025 06:30
@MichaReiser
MichaReiser requested a review from ntBre July 7, 2025 12:56
@MichaReiser MichaReiser added the rule Implementing or modifying a lint rule label Jul 7, 2025

@ntBre ntBre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, this looks good to me! Just a couple of small nits and the merge conflicts, if you don't mind resolving those.

Comment thread crates/ruff_linter/src/rules/flake8_gettext/mod.rs
Comment thread crates/ruff_linter/src/rules/flake8_gettext/mod.rs
@ntBre ntBre added the preview Related to preview-mode features label Jul 21, 2025
@MichaReiser

Copy link
Copy Markdown
Member

@robsdedude do you think you get a chance to resolve the merge conflicts or would you prefer us to resolve them?

Co-authored-by: Brent Westbrook <[email protected]>
@MichaReiser
MichaReiser requested a review from ntBre October 12, 2025 06:43
@robsdedude

Copy link
Copy Markdown
Contributor Author

Ok, this should be good for another review now. Sorry for the long wait. Life got in the way ;)

@ntBre ntBre changed the title [flake8_gettext] Expand scope of INTxxx rules [flake8-gettext] Resolve qualified names and built-in bindings (INT001, INT002, INT003) Oct 20, 2025

@ntBre ntBre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!

@ntBre
ntBre merged commit 511710e into astral-sh:main Oct 20, 2025
37 checks passed
@robsdedude
robsdedude deleted the fix/19028-flake8-gettext-false-negative branch October 21, 2025 05:32
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.

INT rules have false negatives for other ways to use gettext functions

3 participants