jorenham/scipy-stubs

specializing `scipy.optimize.OptimizeResult`

Closed this issue · 0 comments

Currently scipy.optimize.OptimizeResult is annotated for (only) scipy.optimize.minimize, and e.g. annotates x as a 1-d float64 array.
But this isn't always compatible with other functions and methods that also return an OptimizeResult, e.g. minimize_scalar returns it, but has x: np.float64.

This can be fixed by removing most such attributes from OptimizeResult and using specialized @type_check_only subtypes of it as return type.
If attributes such as x turn out to be universal, then type parameters could also be used for these.