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

Add tool to catch the shadowing of _ (gettext) #1721

Open
bmispelon opened this issue Nov 5, 2024 · 4 comments
Open

Add tool to catch the shadowing of _ (gettext) #1721

bmispelon opened this issue Nov 5, 2024 · 4 comments

Comments

@bmispelon
Copy link
Member

With the fantastic work that's been going on to make the site translatable, we've been using the _ alias for gettext more and more throughout the codebase.

Unfortunately, the name _ is also sometimes used to create throwaway variables, and this can lead to crashes (see e995213).

It would be nice if he had a tool to warn us when reusing the name _ for a throwaway variable in a file that already has _ as an alias for gettext. I'm hoping there's already a flake8 plugin for it, or something similar.

@bmispelon
Copy link
Member Author

@marksweb tagging you in just in case you know of existing solutions. This is something I didn't think of when doing the code review, I'll try to pay more attention next time.

@marksweb
Copy link
Contributor

marksweb commented Nov 5, 2024

Oh sorry I missed this one.

Historically when I've had this issue I change the import alias because the underscore is the unused variable standard.

@bmispelon
Copy link
Member Author

For now I've used git grep -E '\b_[^(_a-zA-Z9-9]' -- '*.py' to check for usage of the throwaway _ variable and I'm confident that we don't have other instances of this error currently.

I've looked around a bit and haven't found any available plugins, so this might need to be custom-made 🤔

@marksweb
Copy link
Contributor

marksweb commented Nov 6, 2024

@bmispelon yeah I've not found anything either. Could likely set that up as a workflow action to run on PRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants