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

RUF027: false positive for gettext translation strings #10023

Closed
spaceone opened this issue Feb 18, 2024 · 4 comments · Fixed by #10118
Closed

RUF027: false positive for gettext translation strings #10023

spaceone opened this issue Feb 18, 2024 · 4 comments · Fixed by #10118
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@spaceone
Copy link
Contributor

bar = 'something'
foo = _('my translation {bar}')

# later: foo.format(bar=bar)

is detected as RUF027 Possible f-string without an "f" prefix.

I consider this false-positive, as strings in _() should never be f strings or otherwise formatted.

@charliermarsh
Copy link
Member

Makes sense, we’ll omit these.

@charliermarsh charliermarsh added bug Something isn't working good first issue Good for newcomers labels Feb 18, 2024
@robincaloudis
Copy link
Contributor

robincaloudis commented Feb 22, 2024

Hey @charliermarsh, seems like a good issue for a newby in the ruff code base. I'd like to give it a shot.

@charliermarsh
Copy link
Member

Go for it @robincaloudis! Thanks!

@robincaloudis
Copy link
Contributor

Hey @charliermarsh, do you mind to review #10118? Thank you.

charliermarsh added a commit that referenced this issue Feb 25, 2024
…#10118)

## Summary

It is a convention to use the `_()` alias for `gettext()`. We want to
avoid
statement expressions and assignments related to aliases of the gettext
API.
See https://docs.python.org/3/library/gettext.html for details. When one
uses `_() to mark a string for translation, the tools look for these
markers
and replace the original string with its translated counterpart. If the
string contains variable placeholders or formatting, it can complicate
the
translation process, lead to errors or incorrect translations.

## Test Plan

* Test file `RUF027_1.py` was extended such that the test reproduces the
false-positive

Closes #10023.

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
nkxxll pushed a commit to nkxxll/ruff that referenced this issue Mar 10, 2024
…astral-sh#10118)

## Summary

It is a convention to use the `_()` alias for `gettext()`. We want to
avoid
statement expressions and assignments related to aliases of the gettext
API.
See https://docs.python.org/3/library/gettext.html for details. When one
uses `_() to mark a string for translation, the tools look for these
markers
and replace the original string with its translated counterpart. If the
string contains variable placeholders or formatting, it can complicate
the
translation process, lead to errors or incorrect translations.

## Test Plan

* Test file `RUF027_1.py` was extended such that the test reproduces the
false-positive

Closes astral-sh#10023.

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants