I created a package "mypackage" that uses typing hints.
I import mypackage in a new module (not part of mypackage), mymodule, that also used typing hints.
I would like to apply mypy on mymodule, but get:
error: Cannot find implementation or library stub for module named 'mypackage'
I have been reading the documentation about stubs:
https://mypy.readthedocs.io/en/stable/stubs.html#stub-files
Yet, it is unclear to me what the best practices are.
Here something that works, but feels inefficient.
- I create a package "mypackage". All the code is typed.
- I call stubgen at the root of the package, it creates the folder ./out/mypackage with the stub files
- I move this generated directory to a folder which has the stubs for my other packages, e.g. /path/to/stubs
- I set the environment variable MYPYPATH to /path/to/stubs
mypy mymodule.py
now works, but is this the best way of doing things?
- the information about the types is already in the source code, yet the information is duplicated in pyi files
- we work as a group: everybody has to generate the stubs and copy them to their local stubs folder
- everybody has to regenerate the stubs again when the code is updated
Most likely, I am missing something. Is there a simpler way to apply mypy to mymodule ?