Skip to content
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

[question] How to find pyi stubs? #3626

Closed
asvetlov opened this issue Jun 28, 2017 · 5 comments
Closed

[question] How to find pyi stubs? #3626

asvetlov opened this issue Jun 28, 2017 · 5 comments

Comments

@asvetlov
Copy link

asvetlov commented Jun 28, 2017

I want to enable mypy checks for yarl library.
The library depends on multidict.
Multdict itself has stub annotation file __init__.pyi (I should use stubs because multidict has Cython C Extensions thus I need support stubs for both Python and C Accelerator versions).
__init__.pyi is included in both .tar.gz and .whl distribution files and uploaded to PyPI.

In yarl I use __init__.pyi stub also.
Now in yarl project I run mypy -p yarl.
Report is:

yarl/__init__.pyi:2: error: Cannot find module named 'multidict'
yarl/__init__.pyi:2: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help)
yarl/quoting.py:168: error: Cannot find module named 'yarl._quoting'

'yarl._quoting' is another C Extension, I'll cope with it later.

Cannot find module named 'multidict' is the source of my problem. The module is definitely present and was installed by pip install multidict. Binary wheel with compiled .so files is used.
.../site-packages/multidict/__init__.pyi is present along with .../site-packages/multidict/__init__.py.
import multidict works without problem.
Why mypy doesn't find info about multidict module?

I use fresh virtual environment with mypy and multidict installed.
Python==3.6.1
MyPy==0.511

@JelleZijlstra
Copy link
Member

Mypy does not look at Python-installed packages by default; it only looks at stubs from typeshed and those accessible through paths in the MYPYPATH environment variable. I'm working on a proposal (see python/typing#84) to provide a way for third-party packages to install their stubs in a place where mypy can find them.

@asvetlov
Copy link
Author

IIRC the mentioned issue is about separate stub libraries.
But I have distributed multidict/__init__.pyi alongside with multidict/__init__.pyi.
[MyPy documentation[(http://mypy.readthedocs.io/en/latest/basics.html#library-stubs-and-the-typeshed-repo) allows this case, isn't it?

Using MYPYPATH for pointing on all installed dependencies is too tedious, and the doc explicitly discourages adding site-packages into MYPYPATH.

Moreover if I have well-annotated dependency library without stubs mypy ignores it until I add a path to its source code in MYPYPATH if I understand situation correctly.

That's sad.

Is there workaround for this?
Maybe I need write a script for analyzing my project's dependencies and pushing them into MYPYPATH?

@JelleZijlstra
Copy link
Member

Yes, the proposed solution would be that libraries that distribute pyi files put them in some dedicated directory other than site-packages. Until then, I'm afraid you will have to manually work with MYPYPATH.

@asvetlov
Copy link
Author

Ok. Thanks.
Perhaps we can close the issue but please point me on source for tracing the state.
Is it new PEP or python/typing#84 is just enough?

@JukkaL
Copy link
Collaborator

JukkaL commented Jun 29, 2017

Pointing MYPYPATH to site-packages is not a good option, since it's likely that there are some modules there that aren't designed to work with mypy, even if some of them have stubs. Mypy would try to process everything in there. I'm sure python/typing#84 will be updated when there is progress on this issue.

@JukkaL JukkaL closed this as completed Jun 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants