-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
mypy report custom builtins as not defined #12172
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
mypy doesn't have a solution for monkeypatching. You could try adding |
We received many similar requests from pyright users. There are a couple of use cases. One is monkey-patching of the builtins namespace (which I agree is a really bad idea and should be discouraged). It's also useful for supporting Python distros that add new symbols to the builtins namespace (which is a more legit use case). After exploring various options, I decided to add support for a special I implemented this feature a couple of weeks ago. So far, it seems to be working really well for pyright users, and it was simple to implement. Not only does it work for type checking, it also works with other language server features like completion suggestions. Here's the documentation with additional details. If that solution sounds good generally, perhaps mypy and other Python type checkers would like to adopt this same approach? I can see value in standardizing on a solution. |
Any solution for mypy? |
Bug Report
I'm using the package
gettext
from the standard lib to translate texts inside the application. This will install the function_()
in Python’s builtins namespace,When registering a custom built-in in Pythons namespace then mypy does not recognize that as such and reports it as an unknown.
To Reproduce
Below is an example code that registers the
_
as a bultin-in which can then be used as a standalone function in the codeRunning mypy on this piece of code will report the following:
Expected Behavior
mypy should not report on custom defined built-ins that have been registered dynamically in the code.
A possible solution could be to do something similar to flake8 which allows to specify a config parameter
Actual Behavior
Reports that the dynamically defined builtins are not defined.
Your Environment
mypy.ini
(and other config files): NoneThe text was updated successfully, but these errors were encountered: