Typing stubs for SciPy.
pip install scipy-stubs
The entire public API of scipy
is fully annotated and verifiably valid.
For the most part, this can also be said about scipy
's private API and other internal machinery.
However, a small portion uses Untyped
(and alias of Any
) as "placeholder annotations".
In those cases static type-checkers won't do any type-checking, and won't bother you with errors or warnings.
The following table shows the (subjective) proportion of scipy-stubs
that is(n't) annotated with Untyped
, ranging
from 🌑 (100% Untyped
) to 🌕 (0% Untyped
).
scipy._ |
ruff & flake8-pyi |
stubtest |
basedmypy |
basedpyright |
phase |
---|---|---|---|---|---|
cluster |
✔️ | ✔️ | ✔️ | ✔️ | 🌕 |
constants |
✔️ | ✔️ | ✔️ | ✔️ | 🌝 |
datasets |
✔️ | ✔️ | ✔️ | ✔️ | 🌝 |
fft |
✔️ | ✔️ | ✔️ | ✔️ | 🌔 |
fftpack |
✔️ | ✔️ | ✔️ | ✔️ | 🌔 |
integrate |
✔️ | ✔️ | ✔️ | ✔️ | 🌔 |
interpolate |
✔️ | ✔️ | ✔️ | ✔️ | 🌓 |
io |
✔️ | ✔️ | ✔️ | ✔️ | 🌕 |
linalg |
✔️ | ✔️ | ✔️ | ✔️ | 🌕 |
misc |
✔️ | ✔️ | ✔️ | ✔️ | 🌕 |
ndimage |
✔️ | ✔️ | ✔️ | ✔️ | 🌕 |
odr |
✔️ | ✔️ | ✔️ | ✔️ | 🌕 |
optimize |
✔️ | ✔️ | ✔️ | ✔️ | 🌓 |
signal |
✔️ | ✔️ | ✔️ | ✔️ | 🌓 |
sparse |
✔️ | ✔️ | ✔️ | ✔️ | 🌒 |
spatial |
✔️ | ✔️ | ✔️ | ✔️ | 🌕 |
special |
✔️ | ✔️ | ✔️ | ✔️ | 🌔 |
stats |
✔️ | ✔️ | ✔️ | ✔️ | 🌕 |
_lib |
✔️ | ✔️ | ✔️ | ✔️ | 🌕 |
basedpyright
(recommended)basedmypy
pyright
mypy
(not recommended, see erictraut/mypy_issues)
For validation and testing, scipy-stubs
primarily uses basedmypy
(a mypy
fork)
and basedpyright
(a pyright
fork).
They are in generally stricter than mypy
and pyright
, so you can assume compatibility with mypy
and pyright
as well.
But if you find that this isn't the case, then don't hesitate to open an issue or submit a pull request.
The versioning scheme of scipy-stubs
includes the compatible scipy
version as {scipy_version}.{stubs_version}
.
Even though scipy-stubs
doesn't enforce an upper bound on the scipy
version, later scipy
versions aren't guaranteed to be
fully compatible.
The supported range of numpy
versions are specified in SPEC 0
, which
scipy-stubs
aims to follow as close as feasible.
Currently, scipy-stubs
has one required dependency: optype
.
This is essential for scipy-stubs
to work properly, as it relies heavily on it for annotating (shaped) array-likes,
scalar-likes, shape-typing in general, and much more.
At the moment, scipy-stubs
requires the latest version optype
.
The exact version requirements are specified in the pyproject.toml
.
- scipy/scipy#21614: On why
scipy-stubs
is a separate package, and not part ofscipy
(yet). - microsoft/python-type-stubs#321: The removal of Microsoft's
scipy-stubs
— that used to be bundled with Pylance — in favor ofscipy-stubs
. optype
: The fundamental typing package that madescipy-stubs
possible.basedpyright
: The recommended type-checker to use withscipy-stubs
.basedmypy
: A less-brokenmypy
fork, with a bunch of cool extra features.