diff --git a/src/numpy-stubs/@test/runtime/legacy/literal.py b/src/numpy-stubs/@test/runtime/legacy/literal.py index 5369d404..a85f1e04 100644 --- a/src/numpy-stubs/@test/runtime/legacy/literal.py +++ b/src/numpy-stubs/@test/runtime/legacy/literal.py @@ -18,7 +18,7 @@ CF = frozenset({None, "C", "F"}) order_list: list[tuple[frozenset[str | None], Callable[..., Any]]] = [ - (KACF, partial(np.ndarray, 1)), + (KACF, partial(np.ndarray.__call__, 1)), (KACF, AR.tobytes), (KACF, partial(AR.astype, int)), (KACF, AR.copy), diff --git a/src/numpy-stubs/__init__.pyi b/src/numpy-stubs/__init__.pyi index 1ac5e4d5..56f64c6d 100644 --- a/src/numpy-stubs/__init__.pyi +++ b/src/numpy-stubs/__init__.pyi @@ -619,7 +619,7 @@ _RealT_co = TypeVar("_RealT_co", covariant=True) _ImagT_co = TypeVar("_ImagT_co", covariant=True) _DTypeT = TypeVar("_DTypeT", bound=dtype) -_DTypeT_co = TypeVar("_DTypeT_co", bound=dtype, covariant=True) +_DTypeT_co = TypeVar("_DTypeT_co", bound=dtype, default=dtype, covariant=True) _FlexDTypeT = TypeVar("_FlexDTypeT", bound=dtype[flexible]) _ArrayT = TypeVar("_ArrayT", bound=_nt.Array) @@ -628,6 +628,7 @@ _NumericArrayT = TypeVar("_NumericArrayT", bound=_nt.Array[number | timedelta64 _ShapeT = TypeVar("_ShapeT", bound=_nt.Shape) _ShapeT_co = TypeVar("_ShapeT_co", bound=_nt.Shape, covariant=True) +_ShapeT0_co = TypeVar("_ShapeT0_co", bound=_nt.Shape, default=_nt.Shape, covariant=True) _Shape1NDT = TypeVar("_Shape1NDT", bound=_nt.Shape1N) _ScalarT = TypeVar("_ScalarT", bound=generic) @@ -998,9 +999,11 @@ _HasTypeWithReal: TypeAlias = _HasType[_HasReal[_T]] _HasTypeWithImag: TypeAlias = _HasType[_HasImag[_T]] @type_check_only -class _HasDType(Protocol[_T_co]): +class _HasDType(Protocol[_T_co, _ShapeT0_co]): @property def dtype(self, /) -> _T_co: ... + @property + def shape(self, /) -> _ShapeT0_co: ... _HasDTypeWithItem: TypeAlias = _HasDType[_HasTypeWithItem[_T]] _HasDTypeWithReal: TypeAlias = _HasDType[_HasTypeWithReal[_T]] @@ -2117,16 +2120,16 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): def __ge__(self, other: _ArrayLikeObject_co, /) -> _nt.Array[bool_]: ... # - def __abs__(self: _HasDType[_HasType[SupportsAbs[_ScalarT]]], /) -> _nt.Array[_ScalarT, _ShapeT_co]: ... + def __abs__(self: _HasDType[_HasType[SupportsAbs[_ScalarT]], _ShapeT], /) -> _nt.Array[_ScalarT, _ShapeT]: ... def __neg__(self: _NumericArrayT, /) -> _NumericArrayT: ... # noqa: PYI019 def __pos__(self: _NumericArrayT, /) -> _NumericArrayT: ... # noqa: PYI019 def __invert__(self: _IntegralArrayT, /) -> _IntegralArrayT: ... # noqa: PYI019 # @overload - def __add__(self: _nt.Array[_ScalarT], x: _nt.Casts[_ScalarT], /) -> _nt.Array[_ScalarT]: ... # type: ignore[overload-overlap] + def __add__(self: _nt.Array[_ScalarT], x: _nt.Casts[_ScalarT], /) -> _nt.Array[_ScalarT]: ... @overload - def __add__(self: _nt.Array[_SelfScalarT], x: _nt.CastsWith[_SelfScalarT, _ScalarT], /) -> _nt.Array[_ScalarT]: ... # type: ignore[overload-overlap] + def __add__(self: _nt.Array[_SelfScalarT], x: _nt.CastsWith[_SelfScalarT, _ScalarT], /) -> _nt.Array[_ScalarT]: ... @overload def __add__(self: _nt.CastsWithBuiltin[_T, _ScalarT], x: _nt.SequenceND[_T], /) -> _nt.Array[_ScalarT]: ... @overload @@ -2138,11 +2141,11 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): @overload def __add__(self: _nt.Array[datetime64], x: _nt.CoTimeDelta_nd, /) -> _nt.Array[datetime64]: ... @overload - def __add__(self: _nt.Array[_nt.co_timedelta], x: _nt.ToDateTime_nd, /) -> _nt.Array[datetime64]: ... + def __add__(self: _nt.Array[_nt.co_timedelta, Any], x: _nt.ToDateTime_nd, /) -> _nt.Array[datetime64]: ... @overload - def __add__(self: _nt.Array[object_], x: object, /) -> _nt.Array[object_]: ... # type: ignore[overload-cannot-match] + def __add__(self: _nt.Array[object_, Any], x: object, /) -> _nt.Array[object_]: ... @overload - def __add__(self: _nt.Array[str_], x: _nt.ToString_nd[_T], /) -> _nt.StringArrayND[_T]: ... + def __add__(self: _nt.Array[str_, Any], x: _nt.ToString_nd[_T], /) -> _nt.StringArrayND[_T]: ... @overload def __add__(self: _nt.StringArrayND[_T], x: _nt.ToString_nd[_T] | _nt.ToStr_nd, /) -> _nt.StringArrayND[_T]: ... @overload @@ -2150,9 +2153,9 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): # @overload - def __radd__(self: _nt.Array[_ScalarT], x: _nt.Casts[_ScalarT], /) -> _nt.Array[_ScalarT]: ... # type: ignore[overload-overlap] + def __radd__(self: _nt.Array[_ScalarT], x: _nt.Casts[_ScalarT], /) -> _nt.Array[_ScalarT]: ... @overload - def __radd__(self: _nt.Array[_SelfScalarT], x: _nt.CastsWith[_SelfScalarT, _ScalarT], /) -> _nt.Array[_ScalarT]: ... # type: ignore[overload-overlap] + def __radd__(self: _nt.Array[_SelfScalarT], x: _nt.CastsWith[_SelfScalarT, _ScalarT], /) -> _nt.Array[_ScalarT]: ... @overload def __radd__(self: _nt.CastsWithBuiltin[_T, _ScalarT], x: _nt.SequenceND[_T], /) -> _nt.Array[_ScalarT]: ... @overload @@ -2164,11 +2167,11 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): @overload def __radd__(self: _nt.Array[datetime64], x: _nt.CoTimeDelta_nd, /) -> _nt.Array[datetime64]: ... @overload - def __radd__(self: _nt.Array[_nt.co_timedelta], x: _nt.ToDateTime_nd, /) -> _nt.Array[datetime64]: ... + def __radd__(self: _nt.Array[_nt.co_timedelta, Any], x: _nt.ToDateTime_nd, /) -> _nt.Array[datetime64]: ... @overload - def __radd__(self: _nt.Array[object_], x: object, /) -> _nt.Array[object_]: ... # type: ignore[overload-cannot-match] + def __radd__(self: _nt.Array[object_, Any], x: object, /) -> _nt.Array[object_]: ... @overload - def __radd__(self: _nt.Array[str_], x: _nt.ToString_nd[_T], /) -> _nt.StringArrayND[_T]: ... + def __radd__(self: _nt.Array[str_, Any], x: _nt.ToString_nd[_T], /) -> _nt.StringArrayND[_T]: ... @overload def __radd__(self: _nt.StringArrayND[_T], x: _nt.ToString_nd[_T] | _nt.ToStr_nd, /) -> _nt.StringArrayND[_T]: ... @overload @@ -2268,7 +2271,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): @overload def __mul__(self: _nt.Array[_CoNumberT], x: _nt.Casts[_CoNumberT], /) -> _nt.Array[_CoNumberT]: ... @overload - def __mul__(self: _nt.Array[_SelfScalarT], x: _nt.CastsWith[_SelfScalarT, _ScalarT], /) -> _nt.Array[_ScalarT]: ... # type: ignore[overload-overlap] + def __mul__(self: _nt.Array[_SelfScalarT], x: _nt.CastsWith[_SelfScalarT, _ScalarT], /) -> _nt.Array[_ScalarT]: ... @overload def __mul__(self: _nt.CastsWithBuiltin[_T, _ScalarT], x: _nt.SequenceND[_T], /) -> _nt.Array[_ScalarT]: ... @overload @@ -2278,11 +2281,11 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): @overload def __mul__(self: _nt.CastsWithComplex[_ScalarT], x: _PyComplexND, /) -> _nt.Array[_ScalarT]: ... @overload - def __mul__(self: _nt.Array[timedelta64], x: _nt.ToFloating_nd, /) -> _nt.Array[timedelta64]: ... + def __mul__(self: _nt.Array[timedelta64, Any], x: _nt.ToFloating_nd, /) -> _nt.Array[timedelta64]: ... @overload - def __mul__(self: _nt.Array[object_], x: object, /) -> _nt.Array[object_]: ... # type: ignore[overload-cannot-match] + def __mul__(self: _nt.Array[object_, Any], x: object, /) -> _nt.Array[object_]: ... @overload - def __mul__(self: _nt.Array[integer], x: _nt.ToString_nd, /) -> _nt.StringArrayND[_T]: ... + def __mul__(self: _nt.Array[integer, Any], x: _nt.ToString_nd, /) -> _nt.StringArrayND[_T]: ... @overload def __mul__(self: _nt.StringArrayND[_T], x: _nt.ToInteger_nd, /) -> _nt.StringArrayND[_T]: ... @overload @@ -2292,7 +2295,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): @overload def __rmul__(self: _nt.Array[_CoNumberT], x: _nt.Casts[_CoNumberT], /) -> _nt.Array[_CoNumberT]: ... @overload - def __rmul__(self: _nt.Array[_SelfScalarT], x: _nt.CastsWith[_SelfScalarT, _ScalarT], /) -> _nt.Array[_ScalarT]: ... # type: ignore[overload-overlap] + def __rmul__(self: _nt.Array[_SelfScalarT], x: _nt.CastsWith[_SelfScalarT, _ScalarT], /) -> _nt.Array[_ScalarT]: ... @overload def __rmul__(self: _nt.CastsWithBuiltin[_T, _ScalarT], x: _nt.SequenceND[_T], /) -> _nt.Array[_ScalarT]: ... @overload @@ -2302,11 +2305,11 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): @overload def __rmul__(self: _nt.CastsWithComplex[_ScalarT], x: _PyComplexND, /) -> _nt.Array[_ScalarT]: ... @overload - def __rmul__(self: _nt.Array[timedelta64], x: _nt.ToFloating_nd, /) -> _nt.Array[timedelta64]: ... + def __rmul__(self: _nt.Array[timedelta64, Any], x: _nt.ToFloating_nd, /) -> _nt.Array[timedelta64]: ... @overload - def __rmul__(self: _nt.Array[object_], x: object, /) -> _nt.Array[object_]: ... # type: ignore[overload-cannot-match] + def __rmul__(self: _nt.Array[object_, Any], x: object, /) -> _nt.Array[object_]: ... @overload - def __rmul__(self: _nt.Array[integer], x: _nt.ToString_nd, /) -> _nt.StringArrayND[_T]: ... + def __rmul__(self: _nt.Array[integer, Any], x: _nt.ToString_nd, /) -> _nt.StringArrayND[_T]: ... @overload def __rmul__(self: _nt.StringArrayND[_T], x: _nt.ToInteger_nd, /) -> _nt.StringArrayND[_T]: ... @overload @@ -2666,47 +2669,55 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): # @overload - def __divmod__(self: _nt.Array[bool_], x: _nt.ToBool_nd, /) -> _2Tuple[_nt.Array[int8]]: ... + def __divmod__(self: _nt.Array[bool_, _nt.Shape], x: _nt.ToBool_nd, /) -> _2Tuple[_nt.Array[int8]]: ... @overload def __divmod__( - self: _nt.Array[_RealNumberT], x: _nt.Casts[_RealNumberT] | _nt.ToBool_nd, / + self: _nt.Array[_RealNumberT, _nt.Shape], x: _nt.Casts[_RealNumberT, _nt.Shape] | _nt.ToBool_nd, / ) -> _2Tuple[_nt.Array[_RealNumberT]]: ... @overload def __divmod__( - self: _nt.Array[_CoFloatingT], x: _nt.CastsWith[_CoFloatingT, _RealScalarT], / + self: _nt.Array[_CoFloatingT, _nt.Shape], x: _nt.CastsWith[_CoFloatingT, _RealScalarT, _nt.Shape], / ) -> _2Tuple[_nt.Array[_RealScalarT]]: ... @overload - def __divmod__(self: _nt.CastsWithInt[_RealScalarT], x: _PyIntND, /) -> _2Tuple[_nt.Array[_RealScalarT]]: ... + def __divmod__( + self: _nt.CastsWithInt[_RealScalarT, _nt.Shape], x: _PyIntND, / + ) -> _2Tuple[_nt.Array[_RealScalarT]]: ... @overload - def __divmod__(self: _nt.CastsWithFloat[_RealScalarT], x: _PyFloatND, /) -> _2Tuple[_nt.Array[_RealScalarT]]: ... + def __divmod__( + self: _nt.CastsWithFloat[_RealScalarT, _nt.Shape], x: _PyFloatND, / + ) -> _2Tuple[_nt.Array[_RealScalarT]]: ... @overload def __divmod__( - self: _nt.Array[timedelta64], x: _nt.ToTimeDelta_nd, / + self: _nt.Array[timedelta64, _nt.Shape], x: _nt.ToTimeDelta_nd, / ) -> tuple[_nt.Array[int64], _nt.Array[timedelta64]]: ... @overload - def __divmod__(self: _nt.Array[object_], x: object, /) -> _2Tuple[_nt.Array[object_]]: ... + def __divmod__(self: _nt.Array[object_, _nt.Shape], x: object, /) -> _2Tuple[_nt.Array[object_]]: ... # @overload - def __rdivmod__(self: _nt.Array[bool_], x: _nt.ToBool_nd, /) -> _2Tuple[_nt.Array[int8]]: ... + def __rdivmod__(self: _nt.Array[bool_, _nt.Shape], x: _nt.ToBool_nd, /) -> _2Tuple[_nt.Array[int8]]: ... @overload def __rdivmod__( - self: _nt.Array[_RealNumberT], x: _nt.Casts[_RealNumberT] | _nt.ToBool_nd, / + self: _nt.Array[_RealNumberT, _nt.Shape], x: _nt.Casts[_RealNumberT, _nt.Shape] | _nt.ToBool_nd, / ) -> _2Tuple[_nt.Array[_RealNumberT]]: ... @overload def __rdivmod__( - self: _nt.Array[_CoFloatingT], x: _nt.CastsWith[_CoFloatingT, _RealScalarT], / + self: _nt.Array[_CoFloatingT, _nt.Shape], x: _nt.CastsWith[_CoFloatingT, _RealScalarT, _nt.Shape], / ) -> _2Tuple[_nt.Array[_RealScalarT]]: ... @overload - def __rdivmod__(self: _nt.CastsWithInt[_RealScalarT], x: _PyIntND, /) -> _2Tuple[_nt.Array[_RealScalarT]]: ... + def __rdivmod__( + self: _nt.CastsWithInt[_RealScalarT, _nt.Shape], x: _PyIntND, / + ) -> _2Tuple[_nt.Array[_RealScalarT]]: ... @overload - def __rdivmod__(self: _nt.CastsWithFloat[_RealScalarT], x: _PyFloatND, /) -> _2Tuple[_nt.Array[_RealScalarT]]: ... + def __rdivmod__( + self: _nt.CastsWithFloat[_RealScalarT, _nt.Shape], x: _PyFloatND, / + ) -> _2Tuple[_nt.Array[_RealScalarT]]: ... @overload def __rdivmod__( - self: _nt.Array[timedelta64], x: _nt.ToTimeDelta_nd, / + self: _nt.Array[timedelta64, _nt.Shape], x: _nt.ToTimeDelta_nd, / ) -> tuple[_nt.Array[int64], _nt.Array[timedelta64]]: ... @overload - def __rdivmod__(self: _nt.Array[object_], x: object, /) -> _2Tuple[_nt.Array[object_]]: ... + def __rdivmod__(self: _nt.Array[object_, _nt.Shape], x: object, /) -> _2Tuple[_nt.Array[object_]]: ... # @overload