Skip to content

Commit bf78987

Browse files
authored
Merge pull request #683 from numpy/gh-581
2 parents b061b0b + 69928da commit bf78987

5 files changed

Lines changed: 34 additions & 32 deletions

File tree

src/numpy-stubs/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ from ._core.umath import (
335335
vecmat,
336336
)
337337
from ._expired_attrs_2_0 import __expired_attributes__ as __expired_attributes__
338-
from ._globals import _CopyMode
338+
from ._globals import _CopyMode as _CopyMode, _NoValue as _NoValue
339339
from ._pytesttester import PytestTester
340340
from ._typing import (
341341
ArrayLike,

src/numpy-stubs/_core/_multiarray_umath.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,14 +1387,14 @@ def unravel_index(
13871387
#
13881388
@overload
13891389
def ravel_multi_index(
1390-
multi_index: Sequence[_ToInt],
1390+
multi_index: SupportsLenAndGetItem[_ToInt],
13911391
dims: _ShapeLike,
13921392
mode: _ModeKind | tuple[_ModeKind, ...] = "raise",
13931393
order: _OrderCF = "C",
13941394
) -> np.intp: ...
13951395
@overload
13961396
def ravel_multi_index(
1397-
multi_index: Sequence[_nt.ToInteger_1nd],
1397+
multi_index: SupportsLenAndGetItem[_nt.ToInteger_1nd],
13981398
dims: _ShapeLike,
13991399
mode: _ModeKind | tuple[_ModeKind, ...] = "raise",
14001400
order: _OrderCF = "C",

src/numpy-stubs/_core/fromnumeric.pyi

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ def sum(
674674
#
675675
@overload # workaround for microsoft/pyright#10232
676676
def all(
677-
a: _nt._ToArray_nnd[Any],
677+
a: _nt._ToArray_nnd[Any] | None,
678678
axis: None = None,
679679
out: None = None,
680680
keepdims: _Option[L[False, 0]] = ...,
@@ -683,7 +683,7 @@ def all(
683683
) -> np.bool: ...
684684
@overload
685685
def all(
686-
a: ArrayLike,
686+
a: ArrayLike | None,
687687
axis: None = None,
688688
out: None = None,
689689
keepdims: _Option[L[False, 0]] = ...,
@@ -701,7 +701,7 @@ def all(
701701
) -> np.bool | _nt.Array[np.bool]: ...
702702
@overload
703703
def all(
704-
a: _nt.ToGeneric_1ds,
704+
a: _nt.ToGeneric_1ds | None,
705705
axis: int | None = None,
706706
out: None = None,
707707
keepdims: _Option[L[False, 0]] = ...,
@@ -728,7 +728,7 @@ def all(
728728
) -> _nt.Array[np.bool]: ...
729729
@overload
730730
def all(
731-
a: ArrayLike,
731+
a: ArrayLike | None,
732732
axis: int | tuple[int, ...] | None = None,
733733
out: None = None,
734734
keepdims: _Option[_nt.ToBool_0d] = ...,
@@ -737,7 +737,7 @@ def all(
737737
) -> np.bool | _nt.Array[np.bool]: ...
738738
@overload
739739
def all(
740-
a: ArrayLike,
740+
a: ArrayLike | None,
741741
axis: int | tuple[int, ...] | None,
742742
out: _ArrayT,
743743
keepdims: _Option[_nt.ToBool_0d] = ...,
@@ -746,7 +746,7 @@ def all(
746746
) -> _ArrayT: ...
747747
@overload
748748
def all(
749-
a: ArrayLike,
749+
a: ArrayLike | None,
750750
axis: int | tuple[int, ...] | None = None,
751751
*,
752752
out: _ArrayT,
@@ -757,7 +757,7 @@ def all(
757757
# keep in sync with `all`
758758
@overload # workaround for microsoft/pyright#10232
759759
def any(
760-
a: _nt._ToArray_nnd[Any],
760+
a: _nt._ToArray_nnd[Any] | None,
761761
axis: None = None,
762762
out: None = None,
763763
keepdims: _Option[L[False, 0]] = ...,
@@ -766,7 +766,7 @@ def any(
766766
) -> np.bool: ...
767767
@overload
768768
def any(
769-
a: ArrayLike,
769+
a: ArrayLike | None,
770770
axis: None = None,
771771
out: None = None,
772772
keepdims: _Option[L[False, 0]] = ...,
@@ -784,7 +784,7 @@ def any(
784784
) -> np.bool | _nt.Array[np.bool]: ...
785785
@overload
786786
def any(
787-
a: _nt.ToGeneric_1ds,
787+
a: _nt.ToGeneric_1ds | None,
788788
axis: int | None = None,
789789
out: None = None,
790790
keepdims: _Option[L[False, 0]] = ...,
@@ -811,7 +811,7 @@ def any(
811811
) -> _nt.Array[np.bool]: ...
812812
@overload
813813
def any(
814-
a: ArrayLike,
814+
a: ArrayLike | None,
815815
axis: int | tuple[int, ...] | None = None,
816816
out: None = None,
817817
keepdims: _Option[_nt.ToBool_0d] = ...,
@@ -820,7 +820,7 @@ def any(
820820
) -> np.bool | _nt.Array[np.bool]: ...
821821
@overload
822822
def any(
823-
a: ArrayLike,
823+
a: ArrayLike | None,
824824
axis: int | tuple[int, ...] | None,
825825
out: _ArrayT,
826826
keepdims: _Option[_nt.ToBool_0d] = ...,
@@ -829,7 +829,7 @@ def any(
829829
) -> _ArrayT: ...
830830
@overload
831831
def any(
832-
a: ArrayLike,
832+
a: ArrayLike | None,
833833
axis: int | tuple[int, ...] | None = None,
834834
*,
835835
out: _ArrayT,
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from collections.abc import Callable, Iterable
2-
from typing import Any, Final, NamedTuple
2+
from typing import Any, Final, NamedTuple, TypeAlias
33
from typing_extensions import ParamSpec, TypeVar
44

5-
from numpy._typing import _SupportsArrayFunc
6-
75
_T = TypeVar("_T")
86
_Tss = ParamSpec("_Tss")
9-
_FuncT = TypeVar("_FuncT", bound=Callable[..., object])
7+
_FuncLikeT = TypeVar("_FuncLikeT", bound=type | Callable[..., object])
8+
9+
_Dispatcher: TypeAlias = Callable[_Tss, Iterable[object]]
1010

1111
###
1212

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

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

2525
#
26-
def verify_matching_signatures(
27-
implementation: Callable[_Tss, object], dispatcher: Callable[_Tss, Iterable[_SupportsArrayFunc]]
28-
) -> None: ...
26+
def verify_matching_signatures(implementation: Callable[_Tss, object], dispatcher: _Dispatcher[_Tss]) -> None: ...
2927

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

4745
#
4846
def array_function_from_dispatcher(
4947
implementation: Callable[_Tss, _T],
5048
module: str | None = None,
5149
verify: bool = True,
5250
docs_from_dispatcher: bool = True,
53-
) -> Callable[[Callable[_Tss, Iterable[_SupportsArrayFunc]]], Callable[_Tss, _T]]: ...
51+
) -> Callable[[_Dispatcher[_Tss]], Callable[_Tss, _T]]: ...

src/numpy-stubs/lib/_iotools.pyi

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
from collections.abc import Callable, Iterable
1+
from collections.abc import Callable, Iterable, Sequence
22
from typing import Any, ClassVar, Final, Literal as L, TypedDict, overload, type_check_only
33
from typing_extensions import TypeVar, Unpack
44

55
import numpy as np
66
import numpy.typing as npt
7+
from numpy._typing._dtype_like import _DTypeLikeNested
78

89
_T = TypeVar("_T")
910

1011
@type_check_only
11-
class _ValidationKwargs(TypedDict, total=False):
12+
class _NameValidatorKwargs(TypedDict, total=False):
1213
excludelist: Iterable[str] | None
1314
deletechars: Iterable[str] | None
1415
case_sensitive: L["upper", "lower"] | bool | None
1516
replace_space: str
1617

1718
###
1819

19-
__docformat__: Final[str] = "restructuredtext en"
20+
__docformat__: Final = "restructuredtext en"
2021

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

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

110114
#
111115
def easy_dtype(
112-
ndtype: npt.DTypeLike,
113-
names: Iterable[str] | None = None,
116+
ndtype: str | Sequence[_DTypeLikeNested],
117+
names: str | Sequence[str] | None = None,
114118
defaultfmt: str = "f%i",
115-
**validationargs: Unpack[_ValidationKwargs],
119+
**validationargs: Unpack[_NameValidatorKwargs],
116120
) -> np.dtype[np.void]: ...

0 commit comments

Comments
 (0)