-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Name '_' is not defined with gettext.install() #8727
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
Comments
I don't think so. It might be possible to do with a plugin? |
Modifying the stubs of builtins in typeshed locally and using Better support for monkeypatching stdlib might be a reasonable feature to have at some point, if we can implement it in a simple enough way. One option would to write a generic plugin for this. |
Is there any way to atleast ignore any |
Pylint has additional-builtins configuration option. It would be great if MyPy had something like this. |
I can spend a full week working on Mypy shortly, is this something I'm likely to be able to do? Is adding a config option to extend the builtins an acceptable solution? If so, can you point me to the code I would need to look at. Thanks. |
Can't speak for the maintainers, but an option that allows me to point to an |
A way that would work right now is to fork typeshed to add |
(Also, I'm not sure a PR adding the ability to inject builtins would be accepted.) |
Indeed that's what I did and I can confirm it works.
Indeed. |
But, that requires cloning and maintaining the typeshed repo, right? That doesn't feel like the right solution to close this ticket. I'm expecting something that can extend Mypy's behaviour without requiring that extra overhead. e.g. Following the suggestion to have a .pyi file that can be used to extend the builtiins; this would only require maintaining a 1 line file to support my example use case. |
Yes, it definitely has some overhead, but on the plus side it doesn't require deep changes to mypy. Another hack that I think would work is to copy just |
Seems the latter is not an option:
|
That unfortunately does not work it seems:
|
Another package that |
Sorry, maybe I misunderstood something. I tried to fork typeshed, modify builtins.pyi and add it to mypy but i got error with this traceback. Am I doing something wrong?
As I undestrand this happens here: Lines 4023 to 4025 in d089891
|
See #9802 The person you quoted was using another function (which does not start with _). |
Any update on implementing a way to ignore the _() that gets installed by gettext? |
My impression from various comments is that this practice is discouraged (even if the gettext documentation has not been updated to say this...), and it's unlikely to be supported any time soon (if ever). I'm fine with closing this issue as wont-fix if any of the mypy developers want to confirm that is the case, rather than just leaving it open as a vague hope that it might happen. |
Monkeypatching builtins to "install" the _() function is frowned upon, and unsupported by mypy[1]. It's also unnecessary, as it's perfectly workable to create a _() function definition and import it where needed. This commit adds `from mcomix.i18n import _` to the imports of all modules that use translations, replacing the monkeypatched global. [1]: python/mypy#8727
Fixes ~300 mypy errors and is highly discouraged, see: python/mypy#8727 python/mypy#9802
I get
Name '_' is not defined
after usinggettext.install()
. Is there some configuration option to specify this is a builtin?The text was updated successfully, but these errors were encountered: