8000 TYP: Backport typing fixes and improvements. by charris · Pull Request #29192 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

TYP: Backport typing fixes and improvements. #29192

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 6 commits into from
Jun 12, 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
6 changes: 3 additions & 3 deletions numpy/_array_api_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ def capabilities(self):
>>> info = np.__array_namespace_info__()
>>> info.capabilities()
{'boolean indexing': True,
'data-dependent shapes': True}
'data-dependent shapes': True,
'max dimensions': 64}

"""
return {
"boolean indexing": True,
"data-dependent shapes": True,
# 'max rank' will be part of the 2024.12 standard
# "max rank": 64,
"max dimensions": 64,
}

def default_device(self):
Expand Down
19 changes: 11 additions & 8 deletions numpy/_core/fromnumeric.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -819,9 +819,10 @@ def sum(
where: _ArrayLikeBool_co = ...,
) -> _ArrayT: ...

# keep in sync with `any`
@overload
def all(
a: ArrayLike,
a: ArrayLike | None,
axis: None = None,
out: None = None,
keepdims: Literal[False, 0] | _NoValueType = ...,
Expand All @@ -830,7 +831,7 @@ def all(
) -> np.bool: ...
@overload
def all(
a: ArrayLike,
a: ArrayLike | None,
axis: int | tuple[int, ...] | None = None,
out: None = None,
keepdims: _BoolLike_co | _NoValueType = ...,
Expand All @@ -839,7 +840,7 @@ def all(
) -> Incomplete: ...
@overload
def all(
a: ArrayLike,
a: ArrayLike | None,
axis: int | tuple[int, ...] | None,
out: _ArrayT,
keepdims: _BoolLike_co | _NoValueType = ...,
Expand All @@ -848,17 +849,18 @@ def all(
) -> _ArrayT: ...
@overload
def all(
a: ArrayLike,
a: ArrayLike | None,
axis: int | tuple[int, ...] | None = None,
*,
out: _ArrayT,
keepdims: _BoolLike_co | _NoValueType = ...,
where: _ArrayLikeBool_co | _NoValueType = ...,
) -> _ArrayT: ...

# keep in sync with `all`
@overload
def any(
a: ArrayLike,
a: ArrayLike | None,
axis: None = None,
out: None = None,
keepdims: Literal[False, 0] | _NoValueType = ...,
Expand All @@ -867,7 +869,7 @@ def any(
) -> np.bool: ...
@overload
def any(
a: ArrayLike,
a: ArrayLike 10000 | None,
axis: int | tuple[int, ...] | None = None,
out: None = None,
keepdims: _BoolLike_co | _NoValueType = ...,
Expand All @@ -876,7 +878,7 @@ def any(
) -> Incomplete: ...
@overload
def any(
a: ArrayLike,
a: ArrayLike | None,
axis: int | tuple[int, ...] | None,
out: _ArrayT,
keepdims: _BoolLike_co | _NoValueType = ...,
Expand All @@ -885,14 +887,15 @@ def any(
) -> _ArrayT: ...
@overload
def any(
a: ArrayLike,
a: ArrayLike | None,
axis: int | tuple[int, ...] | None = None,
*,
out: _ArrayT,
keepdims: _BoolLike_co | _NoValueType = ...,
where: _ArrayLikeBool_co | _NoValueType = ...,
) -> _ArrayT: ...

#
@overload
def cumsum(
a: _ArrayLike[_ScalarT],
Expand Down
38 changes: 16 additions & 22 deletions numpy/_core/multiarray.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -499,34 +499,28 @@ def array(
like: _SupportsArrayFunc | None = ...,
) -> NDArray[Any]: ...

#
@overload
def unravel_index( # type: ignore[misc]
indices: _IntLike_co,
shape: _ShapeLike,
order: _OrderCF = ...,
) -> tuple[intp, ...]: ...
@overload
def unravel_index(
indices: _ArrayLikeInt_co,
shape: _ShapeLike,
order: _OrderCF = ...,
) -> tuple[NDArray[intp], ...]: ...

@overload
def ravel_multi_index( # type: ignore[misc]
multi_index: Sequence[_IntLike_co],
dims: Sequence[SupportsIndex],
mode: _ModeKind | tuple[_ModeKind, ...] = ...,
order: _OrderCF = ...,
def ravel_multi_index(
multi_index: SupportsLenAndGetItem[_IntLike_co],
dims: _ShapeLike,
mode: _ModeKind | tuple[_ModeKind, ...] = "raise",
order: _OrderCF = "C",
) -> intp: ...
@overload
def ravel_multi_index(
multi_index: Sequence[_ArrayLikeInt_co],
dims: Sequence[SupportsIndex],
mode: _ModeKind | tuple[_ModeKind, ...] = ...,
order: _OrderCF = ...,
multi_index: SupportsLenAndGetItem[_ArrayLikeInt_co],
dims: _ShapeLike,
mode: _ModeKind | tuple[_ModeKind, ...] = "raise",
order: _OrderCF = "C",
) -> NDArray[intp]: ...

#
@overload
def unravel_index(indices: _IntLike_co, shape: _ShapeLike, order: _OrderCF = "C") -> tuple[intp, ...]: ...
@overload
def unravel_index(indices: _ArrayLikeInt_co, shape: _ShapeLike, order: _OrderCF = "C") -> tuple[NDArray[intp], ...]: ...

# NOTE: Allow any sequence of array-like objects
@overload
def concatenate( # type: ignore[misc]
Expand Down
3 changes: 2 additions & 1 deletion numpy/f2py/auxfuncs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ from .cfuncs import errmess
__all__ = [
"applyrules",
"containscommon",
"containsderivedtypes",
"debugcapi",
"dictappend",
"errmess",
Expand Down Expand Up @@ -200,7 +201,7 @@ def isintent_inplace(var: _Var) -> bool: ...
def isintent_aux(var: _Var) -> bool: ...

#
def containsderivedtypes(rout: _ROut) -> _Bool: ...
def containsderivedtypes(rout: _ROut) -> L[0, 1]: ...
def containscommon(rout: _ROut) -> _Bool: ...
def hasexternals(rout: _ROut) -> bool: ...
def hasresultnote(rout: _ROut) -> _Bool: ...
Expand Down
3 changes: 0 additions & 3 deletions numpy/f2py/diagnose.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
from _typeshed import StrOrBytesPath

def run_command(cmd: StrOrBytesPath) -> None: ...
def run() -> None: ...
34 changes: 25 additions & 9 deletions numpy/lib/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
from numpy._core.function_base import add_newdoc
from numpy._core.multiarray import add_docstring, tracemalloc_domain

from . import ( # noqa: F401
array_utils,
format,
introspect,
mixins,
npyio,
scimath,
stride_tricks,
)
# all submodules of `lib` are accessible at runtime through `__getattr__`,
# so we implicitly re-export them here
from . import _array_utils_impl as _array_utils_impl
from . import _arraypad_impl as _arraypad_impl
from . import _arraysetops_impl as _arraysetops_impl
from . import _arrayterator_impl as _arrayterator_impl
from . import _datasource as _datasource
from . import _format_impl as _format_impl
from . import _function_base_impl as _function_base_impl
from . import _histograms_impl as _histograms_impl
from . import _index_tricks_impl as _index_tricks_impl
from . import _iotools as _iotools
from . import _nanfunctions_impl as _nanfunctions_impl
from . import _npyio_impl as _npyio_impl
from . import _polynomial_impl as _polynomial_impl
from . import _scimath_impl as _scimath_impl
from . import _shape_base_impl as _shape_base_impl
from . import _stride_tricks_impl as _stride_tricks_impl
from . import _twodim_base_impl as _twodim_base_impl
from . import _type_check_impl as _type_check_impl
from . import _ufunclike_impl as _ufunclike_impl
from . import _utils_impl as _utils_impl
from . import _version as _version
from . import array_utils, format, introspect, mixins, npyio, scimath, stride_tricks
from ._arrayterator_impl import Arrayterator
from ._version import NumpyVersion

Expand All @@ -18,6 +33,7 @@ __all__ = [
"add_docstring",
"add_newdoc",
"array_utils",
"format",
"introspect",
"mixins",
"NumpyVersion",
Expand Down
Loading
0