Skip to content
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
10 changes: 5 additions & 5 deletions src/numpy-stubs/_core/_type_aliases.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Collection
from typing import Any, Final, Literal as L, TypeAlias, TypedDict, type_check_only
from typing import Final, Literal as L, TypeAlias, TypedDict, type_check_only

import numpy as np

Expand Down Expand Up @@ -87,10 +87,10 @@ _extra_aliases: Final[_ExtraAliasesType]

@type_check_only
class _SCTypes(TypedDict):
int: Collection[type[np.signedinteger[Any]]]
uint: Collection[type[np.unsignedinteger[Any]]]
float: Collection[type[np.floating[Any]]]
complex: Collection[type[np.complexfloating[Any, Any]]]
int: Collection[type[np.signedinteger]]
uint: Collection[type[np.unsignedinteger]]
float: Collection[type[np.floating]]
complex: Collection[type[np.complexfloating]]
others: Collection[type[np.flexible | np.bool | np.object_]]

sctypes: Final[_SCTypes]
2 changes: 1 addition & 1 deletion src/numpy-stubs/_core/einsumfunc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ from numpy._typing import (

__all__ = ["einsum", "einsum_path"]

_ArrayT = TypeVar("_ArrayT", bound=NDArray[np.bool | np.number[Any]])
_ArrayT = TypeVar("_ArrayT", bound=NDArray[np.bool | np.number])

_OptimizeKind: TypeAlias = bool | Literal["greedy", "optimal"] | Sequence[Any] | None
_CastingSafe: TypeAlias = Literal["no", "equiv", "safe", "same_kind"]
Expand Down
5 changes: 3 additions & 2 deletions src/numpy-stubs/ctypeslib/_ctypeslib.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ctypes as _ct
import ctypes as ct
from _typeshed import StrOrBytesPath
from collections.abc import Iterable, Sequence
Expand Down Expand Up @@ -151,9 +152,9 @@ def as_ctypes_type(dtype: _DoubleCodes | _DTypeLike[np.double] | type[float | ct
@overload
def as_ctypes_type(dtype: _LongDoubleCodes | _DTypeLike[np.longdouble] | type[ct.c_longdouble]) -> type[ct.c_longdouble]: ...
@overload
def as_ctypes_type(dtype: _VoidDTypeLike) -> type[Any]: ... # `ctypes.Union` or `ctypes.Structure`
def as_ctypes_type(dtype: _VoidDTypeLike) -> _ct._UnionType | _ct._PyCStructType: ...
@overload
def as_ctypes_type(dtype: str) -> type[Any]: ...
def as_ctypes_type(dtype: str) -> type: ...
@overload
def as_array(obj: ct._PointerLike, shape: Sequence[int]) -> NDArray[Any]: ...
@overload
Expand Down
4 changes: 2 additions & 2 deletions src/numpy-stubs/polynomial/chebyshev.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ __all__ = [
"poly2cheb",
]

_SCT = TypeVar("_SCT", bound=np.number[Any] | np.object_)
_SCT = TypeVar("_SCT", bound=np.number | np.object_)

def _cseries_to_zseries(c: npt.NDArray[_SCT]) -> _Series[_SCT]: ...
def _zseries_to_cseries(zs: npt.NDArray[_SCT]) -> _Series[_SCT]: ...
Expand Down Expand Up @@ -131,7 +131,7 @@ chebpts1: _FuncPts[L["chebpts1"]]
chebpts2: _FuncPts[L["chebpts2"]]

# keep in sync with `Chebyshev.interpolate`
_RT = TypeVar("_RT", bound=np.number[Any] | np.bool | np.object_)
_RT = TypeVar("_RT", bound=np.number | np.bool | np.object_)

@overload
def chebinterpolate(
Expand Down
72 changes: 30 additions & 42 deletions src/numpy-stubs/polynomial/polyutils.pyi
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
from collections.abc import Callable, Iterable, Sequence
from typing import (
Any,
Final,
Literal,
SupportsIndex,
TypeAlias,
overload,
)
from typing import Final, Literal, SupportsIndex, TypeAlias, overload
from typing_extensions import TypeVar

import numpy as np
import numpy.typing as npt
from numpy._typing import (
_ArrayLikeComplex_co,
_ArrayLikeFloat_co,
_FloatLike_co,
_NumberLike_co,
)
from numpy._typing import _ArrayLikeComplex_co, _ArrayLikeFloat_co, _FloatLike_co, _NumberLike_co

from ._polytypes import (
_AnyInt,
Expand All @@ -41,7 +29,7 @@ from ._polytypes import (
_Tuple2,
)

__all__: Final[Sequence[str]] = [
__all__ = [
"as_series",
"format_float",
"getdomain",
Expand All @@ -66,7 +54,7 @@ _AnyVanderF: TypeAlias = Callable[

@overload
def as_series(
alist: npt.NDArray[np.integer[Any]] | _FloatArray,
alist: npt.NDArray[np.integer] | _FloatArray,
trim: bool = ...,
) -> list[_FloatSeries]: ...
@overload
Expand All @@ -81,7 +69,7 @@ def as_series(
) -> list[_ObjectSeries]: ...
@overload
def as_series( # type: ignore[overload-overlap]
alist: Iterable[_FloatArray | npt.NDArray[np.integer[Any]]],
alist: Iterable[_FloatArray | npt.NDArray[np.integer]],
trim: bool = ...,
) -> list[_FloatSeries]: ...
@overload
Expand Down Expand Up @@ -115,7 +103,7 @@ _T_seq = TypeVar("_T_seq", bound=_CoefArray | Sequence[_CoefLike_co])
def trimseq(seq: _T_seq) -> _T_seq: ...
@overload
def trimcoef( # type: ignore[overload-overlap]
c: npt.NDArray[np.integer[Any]] | _FloatArray,
c: npt.NDArray[np.integer] | _FloatArray,
tol: _FloatLike_co = ...,
) -> _FloatSeries: ...
@overload
Expand Down Expand Up @@ -145,7 +133,7 @@ def trimcoef(
) -> _ObjectSeries: ...
@overload
def getdomain( # type: ignore[overload-overlap]
x: _FloatArray | npt.NDArray[np.integer[Any]],
x: _FloatArray | npt.NDArray[np.integer],
) -> _Array2[np.float64]: ...
@overload
def getdomain(
Expand All @@ -169,18 +157,18 @@ def getdomain(
) -> _Array2[np.object_]: ...
@overload
def mapparms( # type: ignore[overload-overlap]
old: npt.NDArray[np.floating[Any] | np.integer[Any]],
new: npt.NDArray[np.floating[Any] | np.integer[Any]],
) -> _Tuple2[np.floating[Any]]: ...
old: npt.NDArray[np.floating | np.integer],
new: npt.NDArray[np.floating | np.integer],
) -> _Tuple2[np.floating]: ...
@overload
def mapparms(
old: npt.NDArray[np.number[Any]],
new: npt.NDArray[np.number[Any]],
) -> _Tuple2[np.complexfloating[Any, Any]]: ...
old: npt.NDArray[np.number],
new: npt.NDArray[np.number],
) -> _Tuple2[np.complexfloating]: ...
@overload
def mapparms(
old: npt.NDArray[np.object_ | np.number[Any]],
new: npt.NDArray[np.object_ | np.number[Any]],
old: npt.NDArray[np.object_ | np.number],
new: npt.NDArray[np.object_ | np.number],
) -> _Tuple2[object]: ...
@overload
def mapparms( # type: ignore[overload-overlap]
Expand All @@ -196,12 +184,12 @@ def mapparms(
def mapparms(
old: _SeriesLikeFloat_co,
new: _SeriesLikeFloat_co,
) -> _Tuple2[np.floating[Any]]: ...
) -> _Tuple2[np.floating]: ...
@overload
def mapparms(
old: _SeriesLikeComplex_co,
new: _SeriesLikeComplex_co,
) -> _Tuple2[np.complexfloating[Any, Any]]: ...
) -> _Tuple2[np.complexfloating]: ...
@overload
def mapparms(
old: _SeriesLikeCoef_co,
Expand All @@ -212,30 +200,30 @@ def mapdomain( # type: ignore[overload-overlap]
x: _FloatLike_co,
old: _SeriesLikeFloat_co,
new: _SeriesLikeFloat_co,
) -> np.floating[Any]: ...
) -> np.floating: ...
@overload
def mapdomain(
x: _NumberLike_co,
old: _SeriesLikeComplex_co,
new: _SeriesLikeComplex_co,
) -> np.complexfloating[Any, Any]: ...
) -> np.complexfloating: ...
@overload
def mapdomain( # type: ignore[overload-overlap]
x: npt.NDArray[np.floating[Any] | np.integer[Any]],
old: npt.NDArray[np.floating[Any] | np.integer[Any]],
new: npt.NDArray[np.floating[Any] | np.integer[Any]],
x: npt.NDArray[np.floating | np.integer],
old: npt.NDArray[np.floating | np.integer],
new: npt.NDArray[np.floating | np.integer],
) -> _FloatSeries: ...
@overload
def mapdomain(
x: npt.NDArray[np.number[Any]],
old: npt.NDArray[np.number[Any]],
new: npt.NDArray[np.number[Any]],
x: npt.NDArray[np.number],
old: npt.NDArray[np.number],
new: npt.NDArray[np.number],
) -> _ComplexSeries: ...
@overload
def mapdomain(
x: npt.NDArray[np.object_ | np.number[Any]],
old: npt.NDArray[np.object_ | np.number[Any]],
new: npt.NDArray[np.object_ | np.number[Any]],
x: npt.NDArray[np.object_ | np.number],
old: npt.NDArray[np.object_ | np.number],
new: npt.NDArray[np.object_ | np.number],
) -> _ObjectSeries: ...
@overload
def mapdomain( # type: ignore[overload-overlap]
Expand Down Expand Up @@ -402,7 +390,7 @@ def _fit(
full: Literal[True],
/,
w: _SeriesLikeCoef_co | None = ...,
) -> tuple[_CoefSeries, Sequence[np.inexact[Any] | np.int32]]: ...
) -> tuple[_CoefSeries, Sequence[np.inexact | np.int32]]: ...
@overload
def _fit(
vander_f: _AnyVanderF,
Expand All @@ -414,6 +402,6 @@ def _fit(
*,
full: Literal[True],
w: _SeriesLikeCoef_co | None = ...,
) -> tuple[_CoefSeries, Sequence[np.inexact[Any] | np.int32]]: ...
) -> tuple[_CoefSeries, Sequence[np.inexact | np.int32]]: ...
def _as_int(x: SupportsIndex, desc: str) -> int: ...
def format_float(x: _FloatLike_co, parens: bool = ...) -> str: ...
2 changes: 1 addition & 1 deletion src/numpy-stubs/testing/_private/utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def raises(*args: type[BaseException]) -> Callable[[_FT], _FT]: ...

#
def decorate_methods(
cls: type[Any],
cls: type,
decorator: Callable[[Callable[..., Any]], Any],
testmatch: str | bytes | Pattern[Any] | None = None,
) -> None: ...
Expand Down
2 changes: 1 addition & 1 deletion test/static/accept/arraypad.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import numpy as np
import numpy.typing as npt

def mode_func(
ar: npt.NDArray[np.number[Any]],
ar: npt.NDArray[np.number],
width: tuple[int, int],
iaxis: SupportsIndex,
kwargs: Mapping[str, Any],
Expand Down
5 changes: 2 additions & 3 deletions test/static/accept/arrayprint.pyi
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import contextlib
from collections.abc import Callable
from typing import Any
from typing_extensions import assert_type

import numpy as np
import numpy.typing as npt
from numpy._core.arrayprint import _FormatOptions

AR: npt.NDArray[np.int64]
func_float: Callable[[np.floating[Any]], str]
func_int: Callable[[np.integer[Any]], str]
func_float: Callable[[np.floating], str]
func_int: Callable[[np.integer], str]

assert_type(np.get_printoptions(), _FormatOptions)
assert_type(
Expand Down
5 changes: 3 additions & 2 deletions test/static/accept/ctypeslib.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ctypes as _ct
import ctypes as ct
from typing import Any
from typing_extensions import assert_type
Expand Down Expand Up @@ -43,8 +44,8 @@ assert_type(np.ctypeslib.as_ctypes_type(np.single), type[ct.c_float])
assert_type(np.ctypeslib.as_ctypes_type(np.double), type[ct.c_double])
assert_type(np.ctypeslib.as_ctypes_type(ct.c_double), type[ct.c_double])
assert_type(np.ctypeslib.as_ctypes_type("q"), type[ct.c_longlong])
assert_type(np.ctypeslib.as_ctypes_type([("i8", np.int64), ("f8", np.float64)]), type[Any])
assert_type(np.ctypeslib.as_ctypes_type("i8"), type[Any])
assert_type(np.ctypeslib.as_ctypes_type([("i8", np.int64), ("f8", np.float64)]), _ct._UnionType | _ct._PyCStructType)
assert_type(np.ctypeslib.as_ctypes_type("i8"), type)
assert_type(np.ctypeslib.as_ctypes_type("f8"), type[ct.c_double])

assert_type(np.ctypeslib.as_ctypes(AR_bool.take(0)), ct.c_bool)
Expand Down
8 changes: 4 additions & 4 deletions test/static/accept/dtype.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cs_number: Literal["=L", "i", "c16"]
cs_flex: Literal[">V", "S"]
cs_generic: Literal["H", "U", "h", "|M8[Y]", "?"]

dt_inexact: np.dtype[np.inexact[Any]]
dt_inexact: np.dtype[np.inexact]
dt_string: StringDType

assert_type(np.dtype(np.float64), np.dtype[np.float64])
Expand Down Expand Up @@ -73,8 +73,8 @@ assert_type(np.dtype("u1"), np.dtype[np.uint8])
assert_type(np.dtype("l"), np.dtype[np.long])
assert_type(np.dtype("longlong"), np.dtype[np.longlong])
assert_type(np.dtype(">g"), np.dtype[np.longdouble])
assert_type(np.dtype(cs_integer), np.dtype[np.integer[Any]])
assert_type(np.dtype(cs_number), np.dtype[np.number[Any]])
assert_type(np.dtype(cs_integer), np.dtype[np.integer])
assert_type(np.dtype(cs_number), np.dtype[np.number])
assert_type(np.dtype(cs_flex), np.dtype[np.flexible])
assert_type(np.dtype(cs_generic), np.dtype[np.generic])

Expand All @@ -91,7 +91,7 @@ assert_type(np.dtype(None), np.dtype[np.float64])

# Dypes of dtypes
assert_type(np.dtype(np.dtype(np.float64)), np.dtype[np.float64])
assert_type(np.dtype(dt_inexact), np.dtype[np.inexact[Any]])
assert_type(np.dtype(dt_inexact), np.dtype[np.inexact])

# Parameterized dtypes
assert_type(np.dtype("S8"), np.dtype[Any])
Expand Down
36 changes: 18 additions & 18 deletions test/static/accept/emath.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,45 @@ c16: np.complex128

assert_type(np.emath.sqrt(f8), Any)
assert_type(np.emath.sqrt(AR_f8), npt.NDArray[Any])
assert_type(np.emath.sqrt(c16), np.complexfloating[Any, Any])
assert_type(np.emath.sqrt(AR_c16), npt.NDArray[np.complexfloating[Any, Any]])
assert_type(np.emath.sqrt(c16), np.complexfloating)
assert_type(np.emath.sqrt(AR_c16), npt.NDArray[np.complexfloating])

assert_type(np.emath.log(f8), Any)
assert_type(np.emath.log(AR_f8), npt.NDArray[Any])
assert_type(np.emath.log(c16), np.complexfloating[Any, Any])
assert_type(np.emath.log(AR_c16), npt.NDArray[np.complexfloating[Any, Any]])
assert_type(np.emath.log(c16), np.complexfloating)
assert_type(np.emath.log(AR_c16), npt.NDArray[np.complexfloating])

assert_type(np.emath.log10(f8), Any)
assert_type(np.emath.log10(AR_f8), npt.NDArray[Any])
assert_type(np.emath.log10(c16), np.complexfloating[Any, Any])
assert_type(np.emath.log10(AR_c16), npt.NDArray[np.complexfloating[Any, Any]])
assert_type(np.emath.log10(c16), np.complexfloating)
assert_type(np.emath.log10(AR_c16), npt.NDArray[np.complexfloating])

assert_type(np.emath.log2(f8), Any)
assert_type(np.emath.log2(AR_f8), npt.NDArray[Any])
assert_type(np.emath.log2(c16), np.complexfloating[Any, Any])
assert_type(np.emath.log2(AR_c16), npt.NDArray[np.complexfloating[Any, Any]])
assert_type(np.emath.log2(c16), np.complexfloating)
assert_type(np.emath.log2(AR_c16), npt.NDArray[np.complexfloating])

assert_type(np.emath.logn(f8, 2), Any)
assert_type(np.emath.logn(AR_f8, 4), npt.NDArray[Any])
assert_type(np.emath.logn(f8, 1j), np.complexfloating[Any, Any])
assert_type(np.emath.logn(AR_c16, 1.5), npt.NDArray[np.complexfloating[Any, Any]])
assert_type(np.emath.logn(f8, 1j), np.complexfloating)
assert_type(np.emath.logn(AR_c16, 1.5), npt.NDArray[np.complexfloating])

assert_type(np.emath.power(f8, 2), Any)
assert_type(np.emath.power(AR_f8, 4), npt.NDArray[Any])
assert_type(np.emath.power(f8, 2j), np.complexfloating[Any, Any])
assert_type(np.emath.power(AR_c16, 1.5), npt.NDArray[np.complexfloating[Any, Any]])
assert_type(np.emath.power(f8, 2j), np.complexfloating)
assert_type(np.emath.power(AR_c16, 1.5), npt.NDArray[np.complexfloating])

assert_type(np.emath.arccos(f8), Any)
assert_type(np.emath.arccos(AR_f8), npt.NDArray[Any])
assert_type(np.emath.arccos(c16), np.complexfloating[Any, Any])
assert_type(np.emath.arccos(AR_c16), npt.NDArray[np.complexfloating[Any, Any]])
assert_type(np.emath.arccos(c16), np.complexfloating)
assert_type(np.emath.arccos(AR_c16), npt.NDArray[np.complexfloating])

assert_type(np.emath.arcsin(f8), Any)
assert_type(np.emath.arcsin(AR_f8), npt.NDArray[Any])
assert_type(np.emath.arcsin(c16), np.complexfloating[Any, Any])
assert_type(np.emath.arcsin(AR_c16), npt.NDArray[np.complexfloating[Any, Any]])
assert_type(np.emath.arcsin(c16), np.complexfloating)
assert_type(np.emath.arcsin(AR_c16), npt.NDArray[np.complexfloating])

assert_type(np.emath.arctanh(f8), Any)
assert_type(np.emath.arctanh(AR_f8), npt.NDArray[Any])
assert_type(np.emath.arctanh(c16), np.complexfloating[Any, Any])
assert_type(np.emath.arctanh(AR_c16), npt.NDArray[np.complexfloating[Any, Any]])
assert_type(np.emath.arctanh(c16), np.complexfloating)
assert_type(np.emath.arctanh(AR_c16), npt.NDArray[np.complexfloating])
Loading
Loading