Discussed in #1517
Originally posted by wilgri April 7, 2026
Hello,
I'm using scipy-stubs and I'm new to optype. The following call of newton is flagged by basedpyright in strict mode:
def func(x: ArrayND[np.float64]) -> ArrayND[np.float64]:
return -2 * x + 1
newton(func, x0=np.zeros((2, 4), dtype=float))
I gives
Type "(x: ArrayND[float64, AnyShape]) -> ArrayND[float64, AnyShape]" is not assignable to type "_Fun1D[ToFloat]"
Function return type "ArrayND[float64, AnyShape]" is incompatible with type "ToFloat"
Looking at newton's doc and in practice, func accepts ndarray of floats. What am I doing wrong ?
Looking at scipy.optimize.newton typing, I see that func can be a generic callable _Fun1D with a type variable named _ToFloatT . I'm not sure to understand it entirely but it seems that basedpyright does not find an appropriate overload and defaults _ToFloatT to ToFloat which is incompatible with ArrayND[np.float64]. Is my understanding correct ? In addition I don't understand why arguments are onp.Array1D[np.float64] instead of ArrayND ? I feel like I'm missing something.
How would you type this basic example ?
Discussed in #1517
Originally posted by wilgri April 7, 2026
Hello,
I'm using scipy-stubs and I'm new to optype. The following call of newton is flagged by basedpyright in strict mode:
I gives
Looking at newton's doc and in practice,
funcaccepts ndarray of floats. What am I doing wrong ?Looking at
scipy.optimize.newtontyping, I see thatfunccan be a generic callable_Fun1Dwith a type variable named_ToFloatT. I'm not sure to understand it entirely but it seems that basedpyright does not find an appropriate overload and defaults_ToFloatTtoToFloatwhich is incompatible withArrayND[np.float64]. Is my understanding correct ? In addition I don't understand why arguments areonp.Array1D[np.float64]instead ofArrayND? I feel like I'm missing something.How would you type this basic example ?