The upcoming SciPy 1.18.0 release will deprecate the scipy.spatial.minkowski_distance function (and two similar other functions as well). In scipy-stubs, it’s defined using two overloads, and the deprecation applies to the function as a whole, i.e. all overloads are deprecated.
According to the typing-spec:
With overloaded functions, the decorator may be applied to individual overloads, indicating that the particular overload is deprecated. The decorator may also be applied to the overload implementation function, indicating that the entire function is deprecated.
These are stubs we’re talking about, so there’s no overload implementation function, leaving me no other option than to deprecate each overload:
@overload
@deprecated("This function is deprecated in favor of `scipy.spatial.distance.minkowski` and will be removed in SciPy 1.20.0.")
def minkowski_distance(x: onp.ToFloatND, y: onp.ToFloatND, p: float = 2.0) -> onp.ArrayND[np.float64]: ...
@overload
@deprecated("This function is deprecated in favor of `scipy.spatial.distance.minkowski` and will be removed in SciPy 1.20.0.")
def minkowski_distance(x: onp.ToComplexND, y: onp.ToComplexND, p: float = 2.0) -> onp.ArrayND[np.float64 | np.complex128]: ...
(source)
So could we amend the @deprecated typing spec to say something like "if @deprecated is placed before the first @overload of a function in a type-check-only context (i.e. in .pyi stubs, Protocol, or if TYPE_CHECKING:), it applies to all overloads of that function"?
That way, we could simplify the example:
@deprecated("This function is deprecated in favor of `scipy.spatial.distance.minkowski` and will be removed in SciPy 1.20.0.")
@overload
def minkowski_distance(x: onp.ToFloatND, y: onp.ToFloatND, p: float = 2.0) -> onp.ArrayND[np.float64]: ...
@overload
def minkowski_distance(x: onp.ToComplexND, y: onp.ToComplexND, p: float = 2.0) -> onp.ArrayND[np.float64 | np.complex128]: ...



