'How to point to custom stubs directory in mypy via MYPY environment variable or mypy_path variable
I have created a stub file and put it along side of the original file as suggested. However I get missing library stubs or py.typed marker error. I tried adding the stubs directory using mypy_path variable in my config file. Still getting the same error. Any suggestions?
This is how I am initiating mypy:
mypy --namespace-packages --explicit-package-bases --config-file <setup.cfg> <mypy_file_to_typehint>
My setup.cfg has the following:
[mypy]
mypy_path = <directory path>
Solution 1:[1]
You have to point the mypy_path to the stubs directory containing the stub modules, not to the stub modules themselves.
For example if you generated the stubs using stubgen for module "MODULE" like so: stubgen -m MODULE -o stubs, stubgen will then generate the stubs in stubs/MODULE.
In this case, using pyproject.toml as an example (it's the most modern way to configure tools that support it, and so it's recommended):
[tool.mypy]
mypy_path = "$MYPY_CONFIG_FILE_DIR/stubs"
This assumes stubs is in the same directory as pyproject.toml. If it isn't, adapt the path as needed.
The value of mypy_path should work identically for setup.cfg.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | theberzi |
