Skip to content

♻️ refactor type variable names from _SCT to _ScalarT #476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/_numtype/@test/test_to_array.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ from typing_extensions import TypeVar
import _numtype as _nt
import numpy as np

_SCT = TypeVar("_SCT", bound=np.generic)
_0D: TypeAlias = np.ndarray[tuple[()], np.dtype[_SCT]]
_1D: TypeAlias = np.ndarray[tuple[int], np.dtype[_SCT]]
_2D: TypeAlias = np.ndarray[tuple[int, int], np.dtype[_SCT]]
_3D: TypeAlias = np.ndarray[tuple[int, int, int], np.dtype[_SCT]]
_ND: TypeAlias = np.ndarray[tuple[int, ...], np.dtype[_SCT]]
_ScalarT = TypeVar("_ScalarT", bound=np.generic)
_0D: TypeAlias = np.ndarray[tuple[()], np.dtype[_ScalarT]]
_1D: TypeAlias = np.ndarray[tuple[int], np.dtype[_ScalarT]]
_2D: TypeAlias = np.ndarray[tuple[int, int], np.dtype[_ScalarT]]
_3D: TypeAlias = np.ndarray[tuple[int, int, int], np.dtype[_ScalarT]]
_ND: TypeAlias = np.ndarray[tuple[int, ...], np.dtype[_ScalarT]]

b_0d: bool
i_0d: int
Expand Down
4 changes: 2 additions & 2 deletions src/numpy-stubs/@test/static/accept/array_constructors.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ from typing_extensions import TypeVar, assert_type
import numpy as np
import numpy.typing as npt

_SCT_co = TypeVar("_SCT_co", bound=np.generic, covariant=True)
_ScalarT_co = TypeVar("_ScalarT_co", bound=np.generic, covariant=True)

class MyArray(np.ndarray[tuple[int], np.dtype[_SCT_co]]): ...
class MyArray(np.ndarray[tuple[int], np.dtype[_ScalarT_co]]): ...

i8: np.int64

Expand Down
4 changes: 2 additions & 2 deletions src/numpy-stubs/@test/static/accept/multiarray.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import numpy.typing as npt

###

_SCT_co = TypeVar("_SCT_co", bound=np.generic, covariant=True)
_ScalarT_co = TypeVar("_ScalarT_co", bound=np.generic, covariant=True)

class SubClass(npt.NDArray[_SCT_co]): ...
class SubClass(npt.NDArray[_ScalarT_co]): ...

subclass: SubClass[np.float64]

Expand Down
4 changes: 2 additions & 2 deletions src/numpy-stubs/@test/static/accept/twodim_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ from typing_extensions import TypeVar, assert_type
import numpy as np
import numpy.typing as npt

_SCT = TypeVar("_SCT", bound=np.generic)
_ScalarT = TypeVar("_ScalarT", bound=np.generic)

def func1(ar: npt.NDArray[_SCT], a: int) -> npt.NDArray[_SCT]: ...
def func1(ar: npt.NDArray[_ScalarT], a: int) -> npt.NDArray[_ScalarT]: ...
def func2(ar: npt.NDArray[np.number], a: str) -> npt.NDArray[np.float64]: ...

AR_b: npt.NDArray[np.bool]
Expand Down
2 changes: 1 addition & 1 deletion src/numpy-stubs/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta):
) -> dtype[float64]: ...

# Overload for `dtype` instances, scalar types, and instances that have a
# `dtype: dtype[_SCT]` attribute
# `dtype: dtype[_ScalarT]` attribute
@overload
def __new__( # type: ignore[overload-overlap]
cls,
Expand Down
8 changes: 4 additions & 4 deletions src/numpy-stubs/_core/records.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ __all__ = [
]

_T = TypeVar("_T")
_SCT = TypeVar("_SCT", bound=np.generic)
_ScalarT = TypeVar("_ScalarT", bound=np.generic)
_DTypeT_co = TypeVar("_DTypeT_co", bound=np.dtype, covariant=True)
_ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], covariant=True)

_RecArray: TypeAlias = recarray[Any, np.dtype[_SCT]]
_RecArray: TypeAlias = recarray[Any, np.dtype[_ScalarT]]

@type_check_only
class _SupportsReadInto(Protocol):
Expand Down Expand Up @@ -220,7 +220,7 @@ def fromfile(
# exported in `numpy.rec`
@overload
def array( # type: ignore[overload-overlap]
obj: _SCT | NDArray[_SCT],
obj: _ScalarT | NDArray[_ScalarT],
dtype: None = None,
shape: _ShapeLike | None = None,
offset: int = 0,
Expand All @@ -231,7 +231,7 @@ def array( # type: ignore[overload-overlap]
aligned: bool = False,
byteorder: None = None,
copy: bool = True,
) -> _RecArray[_SCT]: ...
) -> _RecArray[_ScalarT]: ...
@overload
def array(
obj: ArrayLike,
Expand Down
48 changes: 27 additions & 21 deletions src/numpy-stubs/_core/shape_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ __all__ = ["atleast_1d", "atleast_2d", "atleast_3d", "block", "hstack", "stack",

###

_SCT = TypeVar("_SCT", bound=np.generic)
_ScalarT = TypeVar("_ScalarT", bound=np.generic)
_SCT0 = TypeVar("_SCT0", bound=np.generic)
_SCT1 = TypeVar("_SCT1", bound=np.generic)

Expand Down Expand Up @@ -41,11 +41,13 @@ def atleast_1d(a0: _Array1T0, a1: _Array1T1, /) -> tuple[_Array1T0, _Array1T1]:
@overload
def atleast_1d(a0: _Array1T, a1: _Array1T, /, *arys: _Array1T) -> tuple[_Array1T, ...]: ... # type: ignore[overload-overlap]
@overload
def atleast_1d(a0: _ArrayLike[_SCT], /) -> NDArray[_SCT]: ...
def atleast_1d(a0: _ArrayLike[_ScalarT], /) -> NDArray[_ScalarT]: ...
@overload
def atleast_1d(a0: _ArrayLike[_SCT0], a2: _ArrayLike[_SCT1], /) -> tuple[NDArray[_SCT0], NDArray[_SCT1]]: ...
@overload
def atleast_1d(a0: _ArrayLike[_SCT], a2: _ArrayLike[_SCT], /, *arys: _ArrayLike[_SCT]) -> tuple[NDArray[_SCT], ...]: ...
def atleast_1d(
a0: _ArrayLike[_ScalarT], a2: _ArrayLike[_ScalarT], /, *arys: _ArrayLike[_ScalarT]
) -> tuple[NDArray[_ScalarT], ...]: ...
@overload
def atleast_1d(a0: ArrayLike, /) -> NDArray[Any]: ...
@overload
Expand All @@ -61,11 +63,13 @@ def atleast_2d(a0: _Array2T0, a1: _Array2T1, /) -> tuple[_Array2T0, _Array2T1]:
@overload
def atleast_2d(a0: _Array2T, a1: _Array2T, /, *arys: _Array2T) -> tuple[_Array2T, ...]: ... # type: ignore[overload-overlap]
@overload
def atleast_2d(a0: _ArrayLike[_SCT], /) -> NDArray[_SCT]: ...
def atleast_2d(a0: _ArrayLike[_ScalarT], /) -> NDArray[_ScalarT]: ...
@overload
def atleast_2d(a0: _ArrayLike[_SCT0], a2: _ArrayLike[_SCT1], /) -> tuple[NDArray[_SCT0], NDArray[_SCT1]]: ...
@overload
def atleast_2d(a0: _ArrayLike[_SCT], a2: _ArrayLike[_SCT], /, *arys: _ArrayLike[_SCT]) -> tuple[NDArray[_SCT], ...]: ...
def atleast_2d(
a0: _ArrayLike[_ScalarT], a2: _ArrayLike[_ScalarT], /, *arys: _ArrayLike[_ScalarT]
) -> tuple[NDArray[_ScalarT], ...]: ...
@overload
def atleast_2d(a0: ArrayLike, /) -> NDArray[Any]: ...
@overload
Expand All @@ -81,11 +85,13 @@ def atleast_3d(a0: _Array3T0, a1: _Array3T1, /) -> tuple[_Array3T0, _Array3T1]:
@overload
def atleast_3d(a0: _Array3T, a1: _Array3T, /, *arys: _Array3T) -> tuple[_Array3T, ...]: ... # type: ignore[overload-overlap]
@overload
def atleast_3d(a0: _ArrayLike[_SCT], /) -> NDArray[_SCT]: ...
def atleast_3d(a0: _ArrayLike[_ScalarT], /) -> NDArray[_ScalarT]: ...
@overload
def atleast_3d(a0: _ArrayLike[_SCT0], a2: _ArrayLike[_SCT1], /) -> tuple[NDArray[_SCT0], NDArray[_SCT1]]: ...
@overload
def atleast_3d(a0: _ArrayLike[_SCT], a2: _ArrayLike[_SCT], /, *arys: _ArrayLike[_SCT]) -> tuple[NDArray[_SCT], ...]: ...
def atleast_3d(
a0: _ArrayLike[_ScalarT], a2: _ArrayLike[_ScalarT], /, *arys: _ArrayLike[_ScalarT]
) -> tuple[NDArray[_ScalarT], ...]: ...
@overload
def atleast_3d(a0: ArrayLike, /) -> NDArray[Any]: ...
@overload
Expand All @@ -96,18 +102,18 @@ def atleast_3d(a0: ArrayLike, a2: ArrayLike, /, *arys: ArrayLike) -> tuple[NDArr
#
@overload
def vstack(
tup: Sequence[_ArrayLike[_SCT]],
tup: Sequence[_ArrayLike[_ScalarT]],
*,
dtype: None = None,
casting: np._CastingKind = "same_kind",
) -> NDArray[_SCT]: ...
) -> NDArray[_ScalarT]: ...
@overload
def vstack(
tup: Sequence[ArrayLike],
*,
dtype: _DTypeLike[_SCT],
dtype: _DTypeLike[_ScalarT],
casting: np._CastingKind = "same_kind",
) -> NDArray[_SCT]: ...
) -> NDArray[_ScalarT]: ...
@overload
def vstack(
tup: Sequence[ArrayLike],
Expand All @@ -119,18 +125,18 @@ def vstack(
#
@overload
def hstack(
tup: Sequence[_ArrayLike[_SCT]],
tup: Sequence[_ArrayLike[_ScalarT]],
*,
dtype: None = None,
casting: np._CastingKind = "same_kind",
) -> NDArray[_SCT]: ...
) -> NDArray[_ScalarT]: ...
@overload
def hstack(
tup: Sequence[ArrayLike],
*,
dtype: _DTypeLike[_SCT],
dtype: _DTypeLike[_ScalarT],
casting: np._CastingKind = "same_kind",
) -> NDArray[_SCT]: ...
) -> NDArray[_ScalarT]: ...
@overload
def hstack(
tup: Sequence[ArrayLike],
Expand All @@ -142,22 +148,22 @@ def hstack(
#
@overload
def stack(
arrays: Sequence[_ArrayLike[_SCT]],
arrays: Sequence[_ArrayLike[_ScalarT]],
axis: SupportsIndex = 0,
out: None = None,
*,
dtype: None = None,
casting: np._CastingKind = "same_kind",
) -> NDArray[_SCT]: ...
) -> NDArray[_ScalarT]: ...
@overload
def stack(
arrays: Sequence[ArrayLike],
axis: SupportsIndex = 0,
out: None = None,
*,
dtype: _DTypeLike[_SCT],
dtype: _DTypeLike[_ScalarT],
casting: np._CastingKind = "same_kind",
) -> NDArray[_SCT]: ...
) -> NDArray[_ScalarT]: ...
@overload
def stack(
arrays: Sequence[ArrayLike],
Expand Down Expand Up @@ -188,12 +194,12 @@ def stack(

#
@overload
def unstack(array: _ArrayLike[_SCT], /, *, axis: SupportsIndex = 0) -> tuple[NDArray[_SCT], ...]: ...
def unstack(array: _ArrayLike[_ScalarT], /, *, axis: SupportsIndex = 0) -> tuple[NDArray[_ScalarT], ...]: ...
@overload
def unstack(array: ArrayLike, /, *, axis: SupportsIndex = 0) -> tuple[NDArray[Any], ...]: ...

#
@overload
def block(arrays: _ArrayLike[_SCT]) -> NDArray[_SCT]: ...
def block(arrays: _ArrayLike[_ScalarT]) -> NDArray[_ScalarT]: ...
@overload
def block(arrays: ArrayLike) -> NDArray[Any]: ...
8 changes: 4 additions & 4 deletions src/numpy-stubs/lib/_arraypad_impl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ __all__ = ["pad"]

###

_SCT = TypeVar("_SCT", bound=np.generic)
_ScalarT = TypeVar("_ScalarT", bound=np.generic)

_ModeKind: TypeAlias = L[
"constant",
Expand All @@ -35,15 +35,15 @@ class _ModeFunc(Protocol):
# specific modes. Consider adding more overloads to express this in the future.
@overload
def pad(
array: _ArrayLike[_SCT],
array: _ArrayLike[_ScalarT],
pad_width: _ArrayLikeInt,
mode: _ModeKind = ...,
*,
stat_length: _ArrayLikeInt | None = ...,
constant_values: ArrayLike = ...,
end_values: ArrayLike = ...,
reflect_type: L["odd", "even"] = ...,
) -> NDArray[_SCT]: ...
) -> NDArray[_ScalarT]: ...
@overload
def pad(
array: ArrayLike,
Expand All @@ -56,6 +56,6 @@ def pad(
reflect_type: L["odd", "even"] = ...,
) -> NDArray[Any]: ...
@overload
def pad(array: _ArrayLike[_SCT], pad_width: _ArrayLikeInt, mode: _ModeFunc, **kwargs: object) -> NDArray[_SCT]: ...
def pad(array: _ArrayLike[_ScalarT], pad_width: _ArrayLikeInt, mode: _ModeFunc, **kwargs: object) -> NDArray[_ScalarT]: ...
@overload
def pad(array: ArrayLike, pad_width: _ArrayLikeInt, mode: _ModeFunc, **kwargs: object) -> NDArray[Any]: ...
12 changes: 6 additions & 6 deletions src/numpy-stubs/lib/_stride_tricks_impl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ from numpy._typing import ArrayLike, NDArray, _ArrayLike, _Shape, _ShapeLike

__all__ = ["broadcast_arrays", "broadcast_shapes", "broadcast_to"]

_SCT = TypeVar("_SCT", bound=np.generic)
_ScalarT = TypeVar("_ScalarT", bound=np.generic)

class DummyArray:
__array_interface__: dict[str, Any]
Expand All @@ -16,12 +16,12 @@ class DummyArray:

@overload
def as_strided(
x: _ArrayLike[_SCT],
x: _ArrayLike[_ScalarT],
shape: Iterable[int] | None = ...,
strides: Iterable[int] | None = ...,
subok: bool = ...,
writeable: bool = ...,
) -> NDArray[_SCT]: ...
) -> NDArray[_ScalarT]: ...
@overload
def as_strided(
x: ArrayLike,
Expand All @@ -32,13 +32,13 @@ def as_strided(
) -> NDArray[Any]: ...
@overload
def sliding_window_view(
x: _ArrayLike[_SCT],
x: _ArrayLike[_ScalarT],
window_shape: int | Iterable[int],
axis: SupportsIndex | None = ...,
*,
subok: bool = ...,
writeable: bool = ...,
) -> NDArray[_SCT]: ...
) -> NDArray[_ScalarT]: ...
@overload
def sliding_window_view(
x: ArrayLike,
Expand All @@ -49,7 +49,7 @@ def sliding_window_view(
writeable: bool = ...,
) -> NDArray[Any]: ...
@overload
def broadcast_to(array: _ArrayLike[_SCT], shape: int | Iterable[int], subok: bool = ...) -> NDArray[_SCT]: ...
def broadcast_to(array: _ArrayLike[_ScalarT], shape: int | Iterable[int], subok: bool = ...) -> NDArray[_ScalarT]: ...
@overload
def broadcast_to(array: ArrayLike, shape: int | Iterable[int], subok: bool = ...) -> NDArray[Any]: ...
def broadcast_shapes(*args: _ShapeLike) -> _Shape: ...
Expand Down