Skip to content

Conversation

cclauss
Copy link
Contributor

@cclauss cclauss commented Oct 14, 2025

Fixes: #319

% ruff rule INT001

f-string-in-get-text-func-call (INT001)

Derived from the flake8-gettext linter.

What it does

Checks for f-strings in gettext function calls.

Why is this bad?

In the gettext API, the gettext function (often aliased to _) returns
a translation of its input argument by looking it up in a translation
catalog.

Calling gettext with an f-string as its argument can cause unexpected
behavior. Since the f-string is resolved before the function call, the
translation catalog will look up the formatted string, rather than the
f-string template.

Instead, format the value returned by the function call, rather than
its argument.

Example

from gettext import gettext as _

name = "Maria"
_(f"Hello, {name}!")  # Looks for "Hello, Maria!".

Use instead:

from gettext import gettext as _

name = "Maria"
_("Hello, %s!") % name  # Looks for "Hello, %s!".

References

@cclauss cclauss requested review from DhavalGojiya and cunla October 14, 2025 14:29
@cclauss
Copy link
Contributor Author

cclauss commented Oct 14, 2025

pre-commit.ci is working...

@cclauss cclauss force-pushed the ruff-rule-INT001 branch 2 times, most recently from 1a98fb6 to 907b788 Compare October 14, 2025 14:53
Copy link
Member

@DhavalGojiya DhavalGojiya left a comment

Choose a reason for hiding this comment

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

Cool

@cclauss cclauss merged commit 78e2826 into django-commons:master Oct 14, 2025
19 checks passed
@cclauss cclauss deleted the ruff-rule-INT001 branch October 14, 2025 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pre-commit: check yaml is failing mkdocs.yml

2 participants