Precise type-hints for all of SciPy
Project description
scipy-stubs
Precise type hints for all of SciPy.
Highlights
- Works out-of-the-box
- all that's needed is to install
scipy-stubs
- does not require a
mypy
plugin or other configuration - available on PyPI and conda-forge
- all that's needed is to install
- Improves IDE suggestions and autocompletion
- ... even if you don't use static typing in your code
- no additional plugins required
- 0% runtime overhead
- not even a single import is required
- 100% coverage of the public SciPy API
- also covers most of the private API
- Precise type-hinting of dtypes and shape-types
- works with all "array-likes" and "dtype-likes"
- many of the functions that return an array are shape-typed
- shape-typing is optional: all functions still accept arrays with unknown shape-type
- Type-checker agnostic
- works with at least
mypy
,pyright
/pylance andruff
- ... even in the strict mode
- compatible with the Python Typing Spec
- works with at least
- SPEC 0 compliant
- Supports Python โฅ 3.10
- Supports NumPy โฅ 1.24
Installation
PyPI | Conda |
---|---|
pip install scipy-stubs
|
conda install conda-forge::scipy-stubs
|
Supported static type-checkers
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.
Versioning and requirements
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
coverage
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
(an 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 |
โ๏ธ | โ๏ธ | โ๏ธ | โ๏ธ | ๐ |
Currently, only interpolate
, signal
, and sparse
contain Untyped
annotations.
See also
- 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file scipy_stubs-1.14.1.5.tar.gz
.
File metadata
- Download URL: scipy_stubs-1.14.1.5.tar.gz
- Upload date:
- Size: 211.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66c160c6b72b1406edc7827879ef25ea81dc3d95ab7e4af3a2de836f27c26ce6 |
|
MD5 | 6c03b7482d9e2c044171ac2650fcd63e |
|
BLAKE2b-256 | 2e79d9a73d6c215b00b21ed16c6638c72a2ea25392f44348bd512fb7802f2ec4 |
File details
Details for the file scipy_stubs-1.14.1.5-py3-none-any.whl
.
File metadata
- Download URL: scipy_stubs-1.14.1.5-py3-none-any.whl
- Upload date:
- Size: 386.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca927802cae4c83e75b2a4b8c41271f36ebe0d928cee25ef3968e143b1793a75 |
|
MD5 | 49ebb4c648c73f4410e3c0ece120f2ad |
|
BLAKE2b-256 | 5a01166738cea89ca8acacd46ef048b9ea37b5817373c7052bfaadbc6a95bc74 |