scipy-stubs: `scipy.optimize.least_squares` function inferred as module
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
As reported in https://github.com/scipy/scipy-stubs/issues/939, mypy seems to infer scipy.optimize.least_squares as a ModuleType. Other type-checkers (pyright, basedpyright, pyrefly) correctly infer it as a function.
from typing import reveal_type
from scipy.optimize import least_squares
reveal_type(least_squares)
- mypy:
Revealed type is "types.ModuleType" - pyrefly:
revealed type: (fun: (🍝) -> OptimizeResult - (based)pyright:
Type of "least_squares" is "(fun: (🍝) -> OptimizeResult"
(🍝 = the huge function signature)
This seems to occur on (at least) scipy-stubs 1.16.2.0 and 1.16.2.3, using mypy 1.18.2.
To repro, install scipy-stubs[scipy]==1.16.2.3 (currently the latest) from pypi or scipy-typed from conda.
Here's are the relevant bits of code:
optimize/__init__.pyire-exportsfrom ._lsq import least_squaresthrough__all__optimize/_lsq/__init__.pyire-exportsfrom .least_squares import least_squaresthrough__all__optimize/_lsq/least_squares.pyicontains the definition for theleast_squaresfunction
It looks like mypy ignores step optimize/_lsq/__init__.pyi from 2., causing it to resolve the optimize._lsq.least_squares module, instead of (explicitly re-exported) optimize._lsq.least_squares.least_squares function.
I expect to be able to work around this by changing from ._lsq import least_squares in optimize/__init__.pyi to from ._lsq.least_squares import least_squares.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci il report con scipy-stubs[scipy]==1.16.2.3 e mypy 1.18.2, utilizzando l’esempio di reveal_type. Confronta optimize/init.pyi, optimize/_lsq/init.pyi e optimize/_lsq/least_squares.pyi, quindi verifica che l’importazione di scipy.optimize.least_squares riveli la funzione invece di ModuleType.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100