-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Can't use _ in typeshed #9802
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
The problem is likely due to circular references -- clearly gettext.pyi depends on builtins.pyi (since every module does), so adding a dependency on gettext.pyi to builtins.pyi causes problems. I'm sure you have already considered and rejected putting the import at the top of your own source files. I recommend reconsidering that, at least if you want static type checking to work for your code. |
Actually, it works if I change it to:
Still doesn't do anything with So, seems that there may be several parts here:
I could reconsider importing the function, I was just following what seemed to be recommended in the docs, e.g.:
https://docs.python.org/3/library/gettext.html#gettext.install |
We should probably do something about those official recommendations of monkey-patching; we don't go around recommending |
allows the definiton of "_" as function in builtins (e.g via typeshed). fixes issue python#9802
allows the definition of "_" as function in builtins (e.g via typeshed). fixes #9802
allows the definition of "_" as function in builtins (e.g via typeshed). fixes python#9802
Fixes ~300 mypy errors and is highly discouraged, see: python/mypy#8727 python/mypy#9802
As has been recommended as a workaround, I've tried using a custom typeshed directory to modify the builtins that Mypy sees, so that it recognises the
_()
function.When adding to builtins.pyi:
I get:
Also, when I try:
I don't get a crash, but Mypy still doesn't recognise it as a global function. Still producing dozens of:
error: Name '_' is not defined [name-defined]
The text was updated successfully, but these errors were encountered: