Skip to content
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

add scipy-stubs as non-typeshed stub package #18832

Merged
merged 1 commit into from
Mar 24, 2025

Conversation

jorenham
Copy link
Contributor

SciPy itself has no py.typed and barely any stubs, so I wrote scipy-stubs. Recently, it has been accepted as an official scipy project.
This stubs-only package is complete (no untyped) and valid (according to mypy, stubtest, pyright, basedmypy and basedpyright), and carefully annotated (by humans).
And for what it's worth, it's also on the list of mypy_primer projects.

I'm open to any feedback, questions, and ideas in general; no need to hold back :)

Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

imagehash (https://github.com/JohannesBuchner/imagehash)
- imagehash/__init__.py:273: error: Cannot find implementation or library stub for module named "scipy.fftpack"  [import-not-found]
+ imagehash/__init__.py:273: error: Library stubs not installed for "scipy.fftpack"  [import-untyped]
+ imagehash/__init__.py:273: note: Hint: "python3 -m pip install scipy-stubs"
+ imagehash/__init__.py:273: note: (or run "mypy --install-types" to install all missing stub packages)
- imagehash/__init__.py:273: error: Cannot find implementation or library stub for module named "scipy"  [import-not-found]
+ imagehash/__init__.py:273: error: Library stubs not installed for "scipy"  [import-untyped]

streamlit (https://github.com/streamlit/streamlit)
- lib/tests/streamlit/web/server/oidc_mixin_test.py:23:1: note: (or run "mypy --install-types" to install all missing stub packages)
- lib/tests/streamlit/elements/audio_test.py:216:1: error: Cannot find implementation or library stub for module named "scipy.io"  [import-not-found]
+ lib/tests/streamlit/elements/audio_test.py:216:1: error: Library stubs not installed for "scipy.io"  [import-untyped]
+ lib/tests/streamlit/elements/audio_test.py:216:1: note: Hint: "python3 -m pip install scipy-stubs"
+ lib/tests/streamlit/elements/audio_test.py:216:1: note: (or run "mypy --install-types" to install all missing stub packages)

arviz (https://github.com/arviz-devs/arviz)
- arviz/stats/ecdf_utils.py:8: error: Cannot find implementation or library stub for module named "scipy.stats"  [import-not-found]
- arviz/stats/ecdf_utils.py:9: error: Cannot find implementation or library stub for module named "scipy.optimize"  [import-not-found]
+ arviz/stats/ecdf_utils.py:8: error: Library stubs not installed for "scipy.stats"  [import-untyped]
+ arviz/stats/ecdf_utils.py:9: error: Library stubs not installed for "scipy.optimize"  [import-untyped]
- arviz/stats/density_utils.py:6: error: Cannot find implementation or library stub for module named "scipy.fftpack"  [import-not-found]
- arviz/stats/density_utils.py:7: error: Cannot find implementation or library stub for module named "scipy.optimize"  [import-not-found]
- arviz/stats/density_utils.py:8: error: Cannot find implementation or library stub for module named "scipy.signal"  [import-not-found]
- arviz/stats/density_utils.py:9: error: Cannot find implementation or library stub for module named "scipy.signal.windows"  [import-not-found]
- arviz/stats/density_utils.py:10: error: Cannot find implementation or library stub for module named "scipy.sparse"  [import-not-found]
- arviz/stats/density_utils.py:11: error: Cannot find implementation or library stub for module named "scipy.special"  [import-not-found]
+ arviz/stats/density_utils.py:6: error: Library stubs not installed for "scipy.fftpack"  [import-untyped]
+ arviz/stats/density_utils.py:7: error: Library stubs not installed for "scipy.optimize"  [import-untyped]
+ arviz/stats/density_utils.py:8: error: Library stubs not installed for "scipy.signal"  [import-untyped]
+ arviz/stats/density_utils.py:9: error: Library stubs not installed for "scipy.signal.windows"  [import-untyped]
+ arviz/stats/density_utils.py:10: error: Library stubs not installed for "scipy.sparse"  [import-untyped]
+ arviz/stats/density_utils.py:11: error: Library stubs not installed for "scipy.special"  [import-untyped]
- arviz/stats/stats_utils.py:10: error: Cannot find implementation or library stub for module named "scipy.fftpack"  [import-not-found]
- arviz/stats/stats_utils.py:11: error: Cannot find implementation or library stub for module named "scipy.interpolate"  [import-not-found]
- arviz/stats/stats_utils.py:12: error: Cannot find implementation or library stub for module named "scipy.stats.mstats"  [import-not-found]
+ arviz/stats/stats_utils.py:10: error: Library stubs not installed for "scipy.fftpack"  [import-untyped]
+ arviz/stats/stats_utils.py:11: error: Library stubs not installed for "scipy.interpolate"  [import-untyped]
+ arviz/stats/stats_utils.py:12: error: Library stubs not installed for "scipy.stats.mstats"  [import-untyped]
- arviz/stats/stats.py:11: error: Cannot find implementation or library stub for module named "scipy.stats"  [import-not-found]
- arviz/stats/stats.py:11: error: Cannot find implementation or library stub for module named "scipy"  [import-not-found]
+ arviz/stats/stats.py:11: error: Library stubs not installed for "scipy.stats"  [import-untyped]
+ arviz/stats/stats.py:11: error: Library stubs not installed for "scipy"  [import-untyped]
- arviz/stats/stats.py:14: error: Cannot find implementation or library stub for module named "scipy.optimize"  [import-not-found]
+ arviz/stats/stats.py:14: error: Library stubs not installed for "scipy.optimize"  [import-untyped]
- arviz/stats/diagnostics.py:9: error: Cannot find implementation or library stub for module named "scipy"  [import-not-found]
+ arviz/stats/diagnostics.py:9: error: Library stubs not installed for "scipy"  [import-untyped]
- arviz/plots/plot_utils.py:11: error: Cannot find implementation or library stub for module named "scipy.stats"  [import-not-found]
- arviz/plots/plot_utils.py:12: error: Cannot find implementation or library stub for module named "scipy.interpolate"  [import-not-found]
+ arviz/plots/plot_utils.py:11: error: Library stubs not installed for "scipy.stats"  [import-untyped]
+ arviz/plots/plot_utils.py:12: error: Library stubs not installed for "scipy.interpolate"  [import-untyped]
- arviz/plots/parallelplot.py:4: error: Cannot find implementation or library stub for module named "scipy.stats"  [import-not-found]
- arviz/plots/loopitplot.py:4: error: Cannot find implementation or library stub for module named "scipy"  [import-not-found]
- arviz/plots/hdiplot.py:6: error: Cannot find implementation or library stub for module named "scipy.interpolate"  [import-not-found]
- arviz/plots/hdiplot.py:7: error: Cannot find implementation or library stub for module named "scipy.signal"  [import-not-found]
- arviz/plots/ecdfplot.py:6: error: Cannot find implementation or library stub for module named "scipy.stats"  [import-not-found]
+ arviz/plots/parallelplot.py:4: error: Library stubs not installed for "scipy.stats"  [import-untyped]
+ arviz/plots/loopitplot.py:4: error: Library stubs not installed for "scipy"  [import-untyped]
+ arviz/plots/hdiplot.py:6: error: Library stubs not installed for "scipy.interpolate"  [import-untyped]
+ arviz/plots/hdiplot.py:7: error: Library stubs not installed for "scipy.signal"  [import-untyped]
+ arviz/plots/ecdfplot.py:6: error: Library stubs not installed for "scipy.stats"  [import-untyped]
- examples/matplotlib/mpl_styles.py:10: error: Cannot find implementation or library stub for module named "scipy"  [import-not-found]
+ examples/matplotlib/mpl_styles.py:10: error: Library stubs not installed for "scipy"  [import-untyped]
- examples/matplotlib/mpl_plot_ecdf_comparison.py:8: error: Cannot find implementation or library stub for module named "scipy.stats"  [import-not-found]
+ examples/matplotlib/mpl_plot_ecdf_comparison.py:8: error: Library stubs not installed for "scipy.stats"  [import-untyped]
- examples/matplotlib/mpl_plot_ecdf.py:9: error: Cannot find implementation or library stub for module named "scipy.stats"  [import-not-found]
+ examples/matplotlib/mpl_plot_ecdf.py:9: error: Library stubs not installed for "scipy.stats"  [import-untyped]
- examples/bokeh/bokeh_plot_ecdf_comparison.py:7: error: Cannot find implementation or library stub for module named "scipy.stats"  [import-not-found]
- examples/bokeh/bokeh_plot_ecdf.py:6: error: Cannot find implementation or library stub for module named "scipy.stats"  [import-not-found]
+ examples/bokeh/bokeh_plot_ecdf_comparison.py:7: error: Library stubs not installed for "scipy.stats"  [import-untyped]
+ examples/bokeh/bokeh_plot_ecdf.py:6: error: Library stubs not installed for "scipy.stats"  [import-untyped]
- asv_benchmarks/benchmarks/benchmarks.py:5: error: Cannot find implementation or library stub for module named "scipy.stats"  [import-not-found]
+ asv_benchmarks/benchmarks/benchmarks.py:5: error: Library stubs not installed for "scipy.stats"  [import-untyped]
- arviz/tests/base_tests/test_stats_utils.py:7: error: Cannot find implementation or library stub for module named "scipy.special"  [import-not-found]
- arviz/tests/base_tests/test_stats_utils.py:8: error: Cannot find implementation or library stub for module named "scipy.stats"  [import-not-found]
- arviz/tests/base_tests/test_stats_ecdf_utils.py:4: error: Cannot find implementation or library stub for module named "scipy.stats"  [import-not-found]
- arviz/tests/base_tests/test_stats_ecdf_utils.py:4: error: Cannot find implementation or library stub for module named "scipy"  [import-not-found]
+ arviz/tests/base_tests/test_stats_utils.py:7: error: Library stubs not installed for "scipy.special"  [import-untyped]
+ arviz/tests/base_tests/test_stats_utils.py:8: error: Library stubs not installed for "scipy.stats"  [import-untyped]
+ arviz/tests/base_tests/test_stats_ecdf_utils.py:4: error: Library stubs not installed for "scipy.stats"  [import-untyped]
+ arviz/tests/base_tests/test_stats_ecdf_utils.py:4: error: Library stubs not installed for "scipy"  [import-untyped]
- arviz/tests/base_tests/test_diagnostics.py:10: error: Cannot find implementation or library stub for module named "scipy"  [import-not-found]
+ arviz/tests/base_tests/test_diagnostics.py:10: error: Library stubs not installed for "scipy"  [import-untyped]
- arviz/plots/backends/matplotlib/mcseplot.py:5: error: Cannot find implementation or library stub for module named "scipy.stats"  [import-not-found]
+ arviz/plots/backends/matplotlib/mcseplot.py:5: error: Library stubs not installed for "scipy.stats"  [import-untyped]
- arviz/plots/backends/matplotlib/essplot.py:5: error: Cannot find implementation or library stub for module named "scipy.stats"  [import-not-found]
+ arviz/plots/backends/matplotlib/essplot.py:5: error: Library stubs not installed for "scipy.stats"  [import-untyped]
- arviz/plots/backends/matplotlib/bpvplot.py:5: error: Cannot find implementation or library stub for module named "scipy"  [import-not-found]
+ arviz/plots/backends/matplotlib/bpvplot.py:5: error: Library stubs not installed for "scipy"  [import-untyped]
- arviz/plots/backends/bokeh/mcseplot.py:7: error: Cannot find implementation or library stub for module named "scipy.stats"  [import-not-found]
+ arviz/plots/backends/bokeh/mcseplot.py:7: error: Library stubs not installed for "scipy.stats"  [import-untyped]
- arviz/plots/backends/bokeh/essplot.py:6: error: Cannot find implementation or library stub for module named "scipy.stats"  [import-not-found]
+ arviz/plots/backends/bokeh/essplot.py:6: error: Library stubs not installed for "scipy.stats"  [import-untyped]
- arviz/tests/base_tests/test_utils.py:8: error: Cannot find implementation or library stub for module named "scipy.stats"  [import-not-found]
- arviz/tests/base_tests/test_utils.py:8: error: Cannot find implementation or library stub for module named "scipy"  [import-not-found]
+ arviz/tests/base_tests/test_utils.py:8: error: Library stubs not installed for "scipy.stats"  [import-untyped]
+ arviz/tests/base_tests/test_utils.py:8: error: Library stubs not installed for "scipy"  [import-untyped]
- arviz/tests/base_tests/test_stats.py:12: error: Cannot find implementation or library stub for module named "scipy.special"  [import-not-found]
- arviz/tests/base_tests/test_stats.py:13: error: Cannot find implementation or library stub for module named "scipy.stats"  [import-not-found]
+ arviz/tests/base_tests/test_stats.py:12: error: Library stubs not installed for "scipy.special"  [import-untyped]
+ arviz/tests/base_tests/test_stats.py:13: error: Library stubs not installed for "scipy.stats"  [import-untyped]
- arviz/tests/base_tests/test_plots_matplotlib.py:14: error: Cannot find implementation or library stub for module named "scipy.stats"  [import-not-found]
+ arviz/tests/base_tests/test_plots_matplotlib.py:14: error: Library stubs not installed for "scipy.stats"  [import-untyped]
- arviz/tests/base_tests/test_plots_bokeh.py:8: error: Cannot find implementation or library stub for module named "scipy.stats"  [import-not-found]
+ arviz/tests/base_tests/test_plots_bokeh.py:8: error: Library stubs not installed for "scipy.stats"  [import-untyped]
- arviz/plots/backends/bokeh/bpvplot.py:6: error: Cannot find implementation or library stub for module named "scipy"  [import-not-found]
+ arviz/plots/backends/bokeh/bpvplot.py:6: error: Library stubs not installed for "scipy"  [import-untyped]
+ arviz/plots/backends/bokeh/bpvplot.py:6: note: Hint: "python3 -m pip install scipy-stubs"

AutoSplit (https://github.com/Toufool/AutoSplit)
- src/compare.py:8:1: error: Skipping analyzing "scipy": module is installed, but missing library stubs or py.typed marker  [import-untyped]
+ src/compare.py:8:1: error: Library stubs not installed for "scipy"  [import-untyped]
+ src/compare.py:8:1: note: Hint: "python3 -m pip install scipy-stubs"

@ilevkivskyi ilevkivskyi merged commit de3bec4 into python:master Mar 24, 2025
18 checks passed
@jorenham jorenham deleted the scipy-stubs branch March 24, 2025 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants