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
ENH: Publish PEP 561 py.typed markers to allow downstream projects to use static code analysis #17158
Comments
Thanks for opening this issue @Trolldemorted
That is a very big IF. There are some type hints in the SciPy code base, but not many. See the huge list of exclusions in mypy.ini that are needed to make It's actually not 100% clear to me from PEP 561 if it's possible to ship partial support. For example per SciPy submodule. This text implies it: "Package maintainers who wish to support type checking of their code MUST add a marker file named py.typed to their package supporting typing. This marker applies recursively: if a top-level package includes it, all its sub-packages MUST support type checking as well." However, it doesn't actually say that you may place a |
@rgommers I did a quick test and at least with mypy it seems to work. This is what I did: Create the following package structure:
Content of def foo1(x: int) -> float:
return x / 1.5 Content of def foo2(x: str) -> str:
return x + x The other files are empty. Then, in a separate directory I created the following script: from pkg.sub1 import foo1
from pkg.sub2 import foo2
f: float
s: str
f = foo1(42) # good
s = foo2("hello") # good
s = foo1("hello") # bad
f = foo2(42) # bad Then run mypy on this script:
which gives me the following output:
So type hints in Tested with mypy 0.991. |
Great, thanks for that @luator! Okay, that means we can do this per submodule as soon as static typing support for a submodule is complete. The first two candidates are probably |
In the meantime, there's some stubs available at https://github.com/microsoft/python-type-stubs/tree/main/stubs/scipy-stubs that you can download and configure your type checker to point to the folder you installed them in. [mypy]
mypy_path = $MYPY_CONFIG_FILE_DIR/typings There's an open feature request to publish those stubs on PyPI: microsoft/python-type-stubs#211 (As a note: as submodules typing are progressively completed and marked as such with |
Is your feature request related to a problem? Please describe.
Downstream consumers cannot use static code analysis tools against their code that uses scipy.
Describe the solution you'd like.
If the type hints in your code are correct, all you have to do is include a PEP 561
py.typed
marker, and your users will be able to type-check their usage of scipy types and functions.Describe alternatives you've considered.
Publishing dedicated stub packages could also work, but compared to shipping marker files this is much more work
Additional context (e.g. screenshots, GIFs)
No response
The text was updated successfully, but these errors were encountered: