Skip to content

INT false negatives for the plural argument of ngettext #21062

@dscorbett

Description

@dscorbett

Summary

f-string-in-get-text-func-call (INT001), format-in-get-text-func-call (INT002), and printf-in-get-text-func-call (INT003) only check the first argument (singular) of ngettext but skip the second (plural). The reasons to avoid f-strings etc. in the first argument apply equally to the second. This is true whether or not ngettext is imported, and if so whether it is aliased. Example:

$ cat >int00.py <<'# EOF'
from gettext import ngettext
def f(n):
    ngettext("one", f"{n}", n)
    ngettext("one", "{}".format(n), n)
    ngettext("one", "%d" % n, n)
# EOF

$ ruff --isolated check int00.py --select INT001,INT002,INT003
All checks passed!

$ sed '/import/d' int00.py | ruff --isolated check - --select INT001,INT002,INT003
All checks passed!

$ sed '/import/s/$/ as n_/; s/ngettext(/n_(/' int00.py | ruff --isolated check - --select INT001,INT002,INT003
All checks passed!

Version

ruff 0.14.2 (83a3bc4 2025-10-23)

Metadata

Metadata

Assignees

No one assigned

    Labels

    previewRelated to preview mode featuresruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions