-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Newbie question about how to deal with builtins. #7931
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 support this sort of highly dynamic pattern. Ideally you should just import foo directly instead of injecting it into builtins. If you really want it to be a builtin and have mypy understand it, I suppose you could manually edit the typeshed stubs mypy is using to add the |
I'm curious what your use-case for this is, but in any case I don't think mypy would support it. (Discouraging such things is essentially a feature of mypy ;) ) |
Just came across this after googling it. 😁 While I agree Of course it is rather easy to programatically add an import to the thousand of files of that code base, but this generates a bit attrition with people who are not so convinced of mypy's benefits. |
So how do you imagine this could be supported? The simplest thing I can think of is to build your own copy of mypy with one line added to buildings.pyi. |
Actually the easiest way is to fork typeshed to add your change, then use mypy's |
I see two possibilities:
Indeed that's what I did and it works great, with the benefit that now mypy can help catching errors with that name now. Unfortunately that is not as convenient, but doable and worth the effort for large code bases.
A plugin to explicitly add new typesheds to existing modules and/or builtins would work even better, if that's possible. |
Are you reporting a bug, or opening a feature request?
It's a newbie question.
Please insert below the code you are checking with mypy
I defined a class named
Person
and added it into__builtins__
, but mypy could not recognize it. I wonder what I can do to make it work. Thank you.The text was updated successfully, but these errors were encountered: