Distributing type information — typing documentation says
The name of the stub package MUST follow the scheme
foopkg-stubs
for type stubs for the package namedfoopkg
Is this only the case with stubs packages installed to site-packages?
I created a subdirectory for my project-specific stubs:
typings
└── foo-stubs
└── __init__.pyi
and ran mypy with MYPYPATH=typings. I expected mypy to accept “import foo”, but it said
Cannot find implementation or library stub for module named "foo" [import-not-found]
Please note, that at this point neither the environment nor stubs directory contained an implementation for package “foo”, only stubs. Is mypy expected to accept stubs without implementation?
Anyway, then I tried adding a dummy implementation:
typings
└── foo-stubs
└── __init__.pyi
└── foo
└── __init__.py
Now mypy was happy with “import foo” and curiously, it also started using the types from the “foo-stubs” directory, which I did not touch.
Then I removed the implementation and removed the “-stubs” suffix from stubs package:
typings
└── foo
└── __init__.pyi
mypy was happy with this.
So, I’ve found the solution, but the confusion remained. This solution seems to contradict PEP561 and several suggestions I’ve seen elsewhere, where people had fixed their problems by adding the “-stubs” suffix to their stub package directories.
Have I misunderstood PEP561? Is this issue specific to MyPy? Or is it specific to MYPYPATH?