-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
How to typecheck "2nd" party packages? #3350
Comments
You can write or generate your own stubs for Or, assuming the source for |
Sorry for taking so long to respond, but I haven't had the opportunity to try this out until now. Now I've tried both approaches. As I mentioned in my original post, writing or generating stubs incurs an unnecessary maintenance burden I would prefer to avoid, since Pointing MYPYPATH to a cloned repo of Ideally, I would have liked to be able to explicitly whitelist specific packages inside the virtualenv's Or is that something you don't want to support with mypy? |
I'm working on a proposal to standardize a way to have a site-packages-like directory for stubs; see python/typing#84. |
@JelleZijlstra Does that solve the issue I have, though? I don't see the point of using Or can To exemplify, I've solved the issue I describe in the previous posts by having my tox.ini copy
It works, but it's an ugly hack. |
The problem with using |
Note that there is #3169 for preserving existing annotations by |
Just preserving annotations is not quite enough, since some types are inferred. Stubgen would have to type check the code and then print out the inferred types. |
Well, to be honest, I am personally not that enamored with stubs, since I think they are redundant in the same way I think header files are redundant. I see why they exist, and why they might be required in some cases, but I don't understand why they should be required. And as my hacky workaround above shows, they aren't actually necessary at all. A mypy user who wants to utilize 2nd/3rd party Anyway, I'm asking for clarification here because I want to know if you are at all open to the idea of adding the option to whitelist stuff in site-packages. If yes, I could start working on a pull request, but I realize that what I'm asking for might not be general enough for inclusion in mypy, and I don't want to waste time implementing something you don't want at all. |
We are open to the idea, but it's not clear what the option should look like. Preferable a user shouldn't need to know which packages have inline annotations in them -- mypy should be able to figure this out automatically somehow. Perhaps each package should declare the presence of inline annotations. There is more discussion about this topic in #1190. Maybe we should close this issue and continue discussion in #1190? Here's a summary of how this could move forward:
|
Since this is not mypy-specific, I'd suggest continuing in python/typing#84. |
Closing in favor of python/typing#84. |
Let's say we have two separate packages,
a
andb
.b
depends on stuff ina
, soa
is installed whenb
is installed. E.g., there's a module inb
that does the following:If I run
mypy
onb/module.py
I will get the following error:error: Cannot find module named 'a'
, even thougha
is installed in my virtualenv.As I understand it, this is the intended behavior, and the solution is to either append
--ignore-missing-imports
or add stubs to typeshed.The problem in our case is that
a
is a private package we have developed for our own internal use, so typeshed is not an optionmypy --ignore-missing-imports b/module.py
will not be able to verify thatmodule.bar
correctly callsmodule.foo
MYPYPATH
seems to be highly discouraged, and is also not a great option becauseb
might also depend on and install 3rd party stuff that isn't properly type hintedSo basically, my question is this: How can we tell mypy to include the imported package
a
when typecheckingb
?I suppose we could add
.pyi
stubs fora
inside theb
repository and pointMYPYPATH
there, but that is suboptimal as it would require us to maintain the API fora
in two separate repositories, and entirely unnecessary since everything ina
is already properly type hinted.The text was updated successfully, but these errors were encountered: