diff --git a/doc/release/upcoming_changes/28669.new_feature.rst b/doc/release/upcoming_changes/28669.new_feature.rst new file mode 100644 index 000000000000..2953a5123ccc --- /dev/null +++ b/doc/release/upcoming_changes/28669.new_feature.rst @@ -0,0 +1,3 @@ +* The type parameter of ``np.dtype`` now defaults to ``typing.Any``. + This way, static type-checkers will infer ``dtype: np.dtype`` as + ``dtype: np.dtype[Any]``, without reporting an error. diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi index f4ae9eed00c2..b2e95a5feccb 100644 --- a/numpy/__init__.pyi +++ b/numpy/__init__.pyi @@ -816,7 +816,7 @@ _2DShapeT_co = TypeVar("_2DShapeT_co", bound=_2D, covariant=True) _1NShapeT = TypeVar("_1NShapeT", bound=tuple[L[1], Unpack[tuple[L[1], ...]]]) # (1,) | (1, 1) | (1, 1, 1) | ... _SCT = TypeVar("_SCT", bound=generic) -_SCT_co = TypeVar("_SCT_co", bound=generic, covariant=True) +_SCT_co = TypeVar("_SCT_co", bound=generic, default=Any, covariant=True) _NumberT = TypeVar("_NumberT", bound=number[Any]) _RealNumberT = TypeVar("_RealNumberT", bound=floating | integer) _FloatingT_co = TypeVar("_FloatingT_co", bound=floating[Any], default=floating[Any], covariant=True)