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
2 changes: 1 addition & 1 deletion src/numpy-stubs/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ from ._core.umath import (
vecmat,
)
from ._expired_attrs_2_0 import __expired_attributes__ as __expired_attributes__
from ._globals import _CopyMode
from ._globals import _CopyMode as _CopyMode, _NoValue as _NoValue
from ._pytesttester import PytestTester
from ._typing import (
ArrayLike,
Expand Down
4 changes: 2 additions & 2 deletions src/numpy-stubs/_core/_multiarray_umath.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1387,14 +1387,14 @@ def unravel_index(
#
@overload
def ravel_multi_index(
multi_index: Sequence[_ToInt],
multi_index: SupportsLenAndGetItem[_ToInt],
dims: _ShapeLike,
mode: _ModeKind | tuple[_ModeKind, ...] = "raise",
order: _OrderCF = "C",
) -> np.intp: ...
@overload
def ravel_multi_index(
multi_index: Sequence[_nt.ToInteger_1nd],
multi_index: SupportsLenAndGetItem[_nt.ToInteger_1nd],
dims: _ShapeLike,
mode: _ModeKind | tuple[_ModeKind, ...] = "raise",
order: _OrderCF = "C",
Expand Down
24 changes: 12 additions & 12 deletions src/numpy-stubs/_core/fromnumeric.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ def sum(
#
@overload # workaround for microsoft/pyright#10232
def all(
a: _nt._ToArray_nnd[Any],
a: _nt._ToArray_nnd[Any] | None,
axis: None = None,
out: None = None,
keepdims: _Option[L[False, 0]] = ...,
Expand All @@ -683,7 +683,7 @@ def all(
) -> np.bool: ...
@overload
def all(
a: ArrayLike,
a: ArrayLike | None,
axis: None = None,
out: None = None,
keepdims: _Option[L[False, 0]] = ...,
Expand All @@ -701,7 +701,7 @@ def all(
) -> np.bool | _nt.Array[np.bool]: ...
@overload
def all(
a: _nt.ToGeneric_1ds,
a: _nt.ToGeneric_1ds | None,
axis: int | None = None,
out: None = None,
keepdims: _Option[L[False, 0]] = ...,
Expand All @@ -728,7 +728,7 @@ def all(
) -> _nt.Array[np.bool]: ...
@overload
def all(
a: ArrayLike,
a: ArrayLike | None,
axis: int | tuple[int, ...] | None = None,
out: None = None,
keepdims: _Option[_nt.ToBool_0d] = ...,
Expand All @@ -737,7 +737,7 @@ def all(
) -> np.bool | _nt.Array[np.bool]: ...
@overload
def all(
a: ArrayLike,
a: ArrayLike | None,
axis: int | tuple[int, ...] | None,
out: _ArrayT,
keepdims: _Option[_nt.ToBool_0d] = ...,
Expand All @@ -746,7 +746,7 @@ def all(
) -> _ArrayT: ...
@overload
def all(
a: ArrayLike,
a: ArrayLike | None,
axis: int | tuple[int, ...] | None = None,
*,
out: _ArrayT,
Expand All @@ -757,7 +757,7 @@ def all(
# keep in sync with `all`
@overload # workaround for microsoft/pyright#10232
def any(
a: _nt._ToArray_nnd[Any],
a: _nt._ToArray_nnd[Any] | None,
axis: None = None,
out: None = None,
keepdims: _Option[L[False, 0]] = ...,
Expand All @@ -766,7 +766,7 @@ def any(
) -> np.bool: ...
@overload
def any(
a: ArrayLike,
a: ArrayLike | None,
axis: None = None,
out: None = None,
keepdims: _Option[L[False, 0]] = ...,
Expand All @@ -784,7 +784,7 @@ def any(
) -> np.bool | _nt.Array[np.bool]: ...
@overload
def any(
a: _nt.ToGeneric_1ds,
a: _nt.ToGeneric_1ds | None,
axis: int | None = None,
out: None = None,
keepdims: _Option[L[False, 0]] = ...,
Expand All @@ -811,7 +811,7 @@ def any(
) -> _nt.Array[np.bool]: ...
@overload
def any(
a: ArrayLike,
a: ArrayLike | None,
axis: int | tuple[int, ...] | None = None,
out: None = None,
keepdims: _Option[_nt.ToBool_0d] = ...,
Expand All @@ -820,7 +820,7 @@ def any(
) -> np.bool | _nt.Array[np.bool]: ...
@overload
def any(
a: ArrayLike,
a: ArrayLike | None,
axis: int | tuple[int, ...] | None,
out: _ArrayT,
keepdims: _Option[_nt.ToBool_0d] = ...,
Expand All @@ -829,7 +829,7 @@ def any(
) -> _ArrayT: ...
@overload
def any(
a: ArrayLike,
a: ArrayLike | None,
axis: int | tuple[int, ...] | None = None,
*,
out: _ArrayT,
Expand Down
20 changes: 9 additions & 11 deletions src/numpy-stubs/_core/overrides.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from collections.abc import Callable, Iterable
from typing import Any, Final, NamedTuple
from typing import Any, Final, NamedTuple, TypeAlias
from typing_extensions import ParamSpec, TypeVar

from numpy._typing import _SupportsArrayFunc

_T = TypeVar("_T")
_Tss = ParamSpec("_Tss")
_FuncT = TypeVar("_FuncT", bound=Callable[..., object])
_FuncLikeT = TypeVar("_FuncLikeT", bound=type | Callable[..., object])

_Dispatcher: TypeAlias = Callable[_Tss, Iterable[object]]

###

Expand All @@ -20,12 +20,10 @@ class ArgSpec(NamedTuple):
defaults: tuple[Any, ...]

def get_array_function_like_doc(public_api: Callable[..., object], docstring_template: str = "") -> str: ...
def finalize_array_function_like(public_api: _FuncT) -> _FuncT: ...
def finalize_array_function_like(public_api: _FuncLikeT) -> _FuncLikeT: ...

#
def verify_matching_signatures(
implementation: Callable[_Tss, object], dispatcher: Callable[_Tss, Iterable[_SupportsArrayFunc]]
) -> None: ...
def verify_matching_signatures(implementation: Callable[_Tss, object], dispatcher: _Dispatcher[_Tss]) -> None: ...

# NOTE: This actually returns a `_ArrayFunctionDispatcher` callable wrapper object, with
# the original wrapped callable stored in the `._implementation` attribute. It checks
Expand All @@ -38,16 +36,16 @@ def verify_matching_signatures(
# implement, ignoring the many hours that I and other stub maintainers are now losing
# because of this completely unreasonable restriction).
def array_function_dispatch(
dispatcher: Callable[_Tss, Iterable[_SupportsArrayFunc]] | None = None,
dispatcher: _Dispatcher[_Tss] | None = None,
module: str | None = None,
verify: bool = True,
docs_from_dispatcher: bool = False,
) -> Callable[[_FuncT], _FuncT]: ...
) -> Callable[[_FuncLikeT], _FuncLikeT]: ...

#
def array_function_from_dispatcher(
implementation: Callable[_Tss, _T],
module: str | None = None,
verify: bool = True,
docs_from_dispatcher: bool = True,
) -> Callable[[Callable[_Tss, Iterable[_SupportsArrayFunc]]], Callable[_Tss, _T]]: ...
) -> Callable[[_Dispatcher[_Tss]], Callable[_Tss, _T]]: ...
16 changes: 10 additions & 6 deletions src/numpy-stubs/lib/_iotools.pyi
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
from collections.abc import Callable, Iterable
from collections.abc import Callable, Iterable, Sequence
from typing import Any, ClassVar, Final, Literal as L, TypedDict, overload, type_check_only
from typing_extensions import TypeVar, Unpack

import numpy as np
import numpy.typing as npt
from numpy._typing._dtype_like import _DTypeLikeNested

_T = TypeVar("_T")

@type_check_only
class _ValidationKwargs(TypedDict, total=False):
class _NameValidatorKwargs(TypedDict, total=False):
excludelist: Iterable[str] | None
deletechars: Iterable[str] | None
case_sensitive: L["upper", "lower"] | bool | None
replace_space: str

###

__docformat__: Final[str] = "restructuredtext en"
__docformat__: Final = "restructuredtext en"
Comment thread
jorenham marked this conversation as resolved.

class ConverterError(Exception): ...
class ConverterLockError(ConverterError): ...
Expand Down Expand Up @@ -94,6 +95,9 @@ class StringConverter:
@classmethod
def upgrade_mapper(cls, func: Callable[[str], Any], default: object | None = None) -> None: ...

def _decode_line(line: str | bytes, encoding: str | None = None) -> str: ...
def _is_string_like(obj: object) -> bool: ...
def _is_bytes_like(obj: object) -> bool: ...
@overload
def str2bool(value: L["false", "False", "FALSE"]) -> L[False]: ...
@overload
Expand All @@ -109,8 +113,8 @@ def flatten_dtype(

#
def easy_dtype(
ndtype: npt.DTypeLike,
names: Iterable[str] | None = None,
ndtype: str | Sequence[_DTypeLikeNested],
names: str | Sequence[str] | None = None,
defaultfmt: str = "f%i",
**validationargs: Unpack[_ValidationKwargs],
**validationargs: Unpack[_NameValidatorKwargs],
) -> np.dtype[np.void]: ...
Loading