-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
When working on a repo containing types to be distributed in accordance with PEP 561 (such as https://github.com/numpy/numpy-stubs) it is surprisingly difficult to get mypy to actually see and respect those types. In particular, things that do not work (though I would expect them to):
- Adding the directory containing the
-stubs
directory to theMYPYPATH
- Running
python setup.py install
- Running
pip install -e .
I eventually was able to make it work by running pip install .
, but (particularly for things like running py.test
while developing one of these stubs repos) this seems non-optimal.
Interestingly, adding the directory containing the -stubs
directory to MYPYPATH
did allow me to resolve types in the root of the package we care about (in this case numpy
), but not in nested packages (in this case numpy.core
). It looks like this might have something to do with this code where dir_chain
is an empty string when looking for a top-level package and therefore find_lib_path_dirs
doesn't filter out the items in lib_path
. When we're trying to get a nested package it's non-empty and can't be found in the lib_path
dirs, which then get filtered out. We also don't populate third_party_stubs_dirs
in any of the above cases because the items on MYPYPATH
aren't looked at for that (only site packages) and the other two methods don't create a bare directory named -stubs
in the site packages (one creates a .egg
and the other creates a .egg-link
).
I did these experiments on commit 7fe60a547c476c8b341a47b87d72fc4460532102
of mypy with Python 3.6.4 on macOS.
Let me know if there's anything else I can provide which would be helpful! I'm not sure if this is more of a bug or a feature request because I couldn't tell from my reading of PEP 561 whether this use case was covered by that.