2

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>
Anu
  • 101
  • 2
  • 8

1 Answers1

2

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.

theberzi
  • 2,142
  • 3
  • 20
  • 34