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

Fix RUF027 false positives if gettext is imported using an alias #12025

Merged
merged 4 commits into from
Jun 25, 2024

Conversation

AlexWaygood
Copy link
Member

Noticed this while reviewing if it was ready to be stabilised

@AlexWaygood AlexWaygood added the rule Implementing or modifying a lint rule label Jun 25, 2024
Copy link
Contributor

github-actions bot commented Jun 25, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@MichaReiser
Copy link
Member

What's exactly the false positive that this PR fixes?

@charliermarsh
Copy link
Member

I think it's demonstrated in the fixture: aliasing gettext when importing.

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Nice find

@charliermarsh
Copy link
Member

The only risk here is: is gettext ever imported from somewhere else, like django.gettext? (I made that up, I have no idea.)

@charliermarsh
Copy link
Member

We might want to also check the raw name.

@AlexWaygood
Copy link
Member Author

I think it's demonstrated in the fixture: aliasing gettext when importing.

It's actually not currently; Micha made a good point -- there's a bug in my test :-)

But I'll improve the test so that it does actually fail on main

@AlexWaygood
Copy link
Member Author

The only risk here is: is gettext ever imported from somewhere else, like django.gettext? (I made that up, I have no idea.)

Ah yeah, you're right, that's apparently a thing: https://github.com/django/django/blob/d9bd58c3b8b3e8735d8242c2bb9b09c52ed6171b/django/contrib/flatpages/forms.py#L5

gettext is wild!

@charliermarsh
Copy link
Member

I figured there was a reason for this (Chesterton's Fence) hah.

@AlexWaygood AlexWaygood merged commit 00e456e into main Jun 25, 2024
20 checks passed
@AlexWaygood AlexWaygood deleted the fstring-rule-fixup branch June 25, 2024 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants