[flake8-gettext] Fix false negatives for plural argument of ngettext (INT001, INT002, INT003)#21078
Conversation
|
ntBre
left a comment
There was a problem hiding this comment.
Thank you! And sorry for the delay on the review.
I only had a couple of nits about the code, but I think we need to improve the error messages for these new cases. We should also make this a preview change as I mentioned on the issue since this substantially increases the scope of the rule, even if there are no ecosystem changes.
...f_linter__rules__flake8_gettext__tests__preview__printf-in-get-text-func-call_INT003.py.snap
Outdated
Show resolved
Hide resolved
|
Is it worth if we try to push this PR over the line, given that the changes seem pretty minimal |
|
I can take a look this weekend |
ntBre
left a comment
There was a problem hiding this comment.
Thanks! I pushed a couple of commits adding the preview gating and factoring out a couple of helper functions to reuse existing code.
* main: (45 commits) [ty] Fix wrong inlay hints for overloaded function arguments (astral-sh#23179) [ty] Respect `@no_type_check` when combined with other decorators (astral-sh#23177) [ty] Use type context when inferring constructor argument types (astral-sh#23139) [`airflow`] Add ruff rules to catch deprecated attribute access from context key for Airflow 3.0 (`AIR301`) (astral-sh#22850) Support formatting `pycon` markdown code blocks (astral-sh#23112) Markdown formatting in LSP (astral-sh#23063) Instruct Claude to use comments more sparingly (astral-sh#23181) [`flake8-gettext`] Fix false negatives for plural argument of ngettext (`INT001`, `INT002`, `INT003`) (astral-sh#21078) [ty] Invoking goto-def on parentheses of a class constructor call takes you too constructor method [ty] Make goto definition on class constructor always go to class definition [ty] Assign lower completions ranking to deprecated functions and classes (astral-sh#23089) [ty] Fix parameter references across files via keyword args (astral-sh#23012) [ty] Exclude enclosing class for base completions (astral-sh#23141) [`pyupgrade`] Fix syntax error on string with newline escape and comment (`UP037`) (astral-sh#22968) [ty] Improve documentation for `expect_single_definition` method (astral-sh#23175) [ty] Configure check mode for all projects Add `home-assistant` to ecosystem projects (astral-sh#23132) Add tabbed shell completion documentation (astral-sh#23169) Bump typing conformance-suite pin (astral-sh#23174) [ty] Fix invalid diagnostic location for a sub-call to a specialized ParamSpec (astral-sh#23036) ...
Summary
Fixes #21062. Extends the
INT001,INT002, andINT003lint rules to check both the singular and plural arguments ofngettextfunction calls, fixing false negatives where formatting issues in the plural argument were not being detected.Problem Analysis
The three rules (
f-string-in-get-text-func-call,format-in-get-text-func-call, andprintf-in-get-text-func-call) only checked the first argument (singular) ofngettextcalls but ignored the second argument (plural). This caused false negatives when f-strings,.format()calls, or%formatting were used in the plural argument.The root cause was:
args.first()ngettextvsgettextargs.get(1)(the second argument)Example of the bug:
Approach
funcparameteris_ngettext_call()helper that checks:ngettext(...))ngettext(e.g.,gettext_mod.ngettext(...))ngettextcalls, now check both first and second argumentshelpers.rsmodule to eliminate duplicationfuncparameter