GeezerVison is showing github.com — Merge pull request #683 from numpy/gh-581 · numpy/numtype@bf78987
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/numpy-stubs/__init__.pyi +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -335,7 +335,7 @@ from ._core.umath import ( | 335 | 335 | vecmat, | 336 | 336 | ) | 337 | 337 | 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 | 339 | 339 | from ._pytesttester import PytestTester | 340 | 340 | from ._typing import ( | 341 | 341 | ArrayLike, | |
Collapse file Copy file name to clipboardExpand all lines: src/numpy-stubs/_core/_multiarray_umath.pyi +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1387,14 +1387,14 @@ def unravel_index( | 1387 | 1387 | # | 1388 | 1388 | @overload | 1389 | 1389 | def ravel_multi_index( | 1390 | | - multi_index: Sequence[_ToInt], | | 1390 | + multi_index: SupportsLenAndGetItem[_ToInt], | 1391 | 1391 | dims: _ShapeLike, | 1392 | 1392 | mode: _ModeKind | tuple[_ModeKind, ...] = "raise", | 1393 | 1393 | order: _OrderCF = "C", | 1394 | 1394 | ) -> np.intp: ... | 1395 | 1395 | @overload | 1396 | 1396 | def ravel_multi_index( | 1397 | | - multi_index: Sequence[_nt.ToInteger_1nd], | | 1397 | + multi_index: SupportsLenAndGetItem[_nt.ToInteger_1nd], | 1398 | 1398 | dims: _ShapeLike, | 1399 | 1399 | mode: _ModeKind | tuple[_ModeKind, ...] = "raise", | 1400 | 1400 | order: _OrderCF = "C", | |
Collapse file Copy file name to clipboardExpand all lines: src/numpy-stubs/_core/fromnumeric.pyi +12-12Lines changed: 12 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -674,7 +674,7 @@ def sum( | 674 | 674 | # | 675 | 675 | @overload # workaround for microsoft/pyright#10232 | 676 | 676 | def all( | 677 | | - a: _nt._ToArray_nnd[Any], | | 677 | + a: _nt._ToArray_nnd[Any] | None, | 678 | 678 | axis: None = None, | 679 | 679 | out: None = None, | 680 | 680 | keepdims: _Option[L[False, 0]] = ..., | @@ -683,7 +683,7 @@ def all( | 683 | 683 | ) -> np.bool: ... | 684 | 684 | @overload | 685 | 685 | def all( | 686 | | - a: ArrayLike, | | 686 | + a: ArrayLike | None, | 687 | 687 | axis: None = None, | 688 | 688 | out: None = None, | 689 | 689 | keepdims: _Option[L[False, 0]] = ..., | @@ -701,7 +701,7 @@ def all( | 701 | 701 | ) -> np.bool | _nt.Array[np.bool]: ... | 702 | 702 | @overload | 703 | 703 | def all( | 704 | | - a: _nt.ToGeneric_1ds, | | 704 | + a: _nt.ToGeneric_1ds | None, | 705 | 705 | axis: int | None = None, | 706 | 706 | out: None = None, | 707 | 707 | keepdims: _Option[L[False, 0]] = ..., | @@ -728,7 +728,7 @@ def all( | 728 | 728 | ) -> _nt.Array[np.bool]: ... | 729 | 729 | @overload | 730 | 730 | def all( | 731 | | - a: ArrayLike, | | 731 | + a: ArrayLike | None, | 732 | 732 | axis: int | tuple[int, ...] | None = None, | 733 | 733 | out: None = None, | 734 | 734 | keepdims: _Option[_nt.ToBool_0d] = ..., | @@ -737,7 +737,7 @@ def all( | 737 | 737 | ) -> np.bool | _nt.Array[np.bool]: ... | 738 | 738 | @overload | 739 | 739 | def all( | 740 | | - a: ArrayLike, | | 740 | + a: ArrayLike | None, | 741 | 741 | axis: int | tuple[int, ...] | None, | 742 | 742 | out: _ArrayT, | 743 | 743 | keepdims: _Option[_nt.ToBool_0d] = ..., | @@ -746,7 +746,7 @@ def all( | 746 | 746 | ) -> _ArrayT: ... | 747 | 747 | @overload | 748 | 748 | def all( | 749 | | - a: ArrayLike, | | 749 | + a: ArrayLike | None, | 750 | 750 | axis: int | tuple[int, ...] | None = None, | 751 | 751 | *, | 752 | 752 | out: _ArrayT, | @@ -757,7 +757,7 @@ def all( | 757 | 757 | # keep in sync with `all` | 758 | 758 | @overload # workaround for microsoft/pyright#10232 | 759 | 759 | def any( | 760 | | - a: _nt._ToArray_nnd[Any], | | 760 | + a: _nt._ToArray_nnd[Any] | None, | 761 | 761 | axis: None = None, | 762 | 762 | out: None = None, | 763 | 763 | keepdims: _Option[L[False, 0]] = ..., | @@ -766,7 +766,7 @@ def any( | 766 | 766 | ) -> np.bool: ... | 767 | 767 | @overload | 768 | 768 | def any( | 769 | | - a: ArrayLike, | | 769 | + a: ArrayLike | None, | 770 | 770 | axis: None = None, | 771 | 771 | out: None = None, | 772 | 772 | keepdims: _Option[L[False, 0]] = ..., | @@ -784,7 +784,7 @@ def any( | 784 | 784 | ) -> np.bool | _nt.Array[np.bool]: ... | 785 | 785 | @overload | 786 | 786 | def any( | 787 | | - a: _nt.ToGeneric_1ds, | | 787 | + a: _nt.ToGeneric_1ds | None, | 788 | 788 | axis: int | None = None, | 789 | 789 | out: None = None, | 790 | 790 | keepdims: _Option[L[False, 0]] = ..., | @@ -811,7 +811,7 @@ def any( | 811 | 811 | ) -> _nt.Array[np.bool]: ... | 812 | 812 | @overload | 813 | 813 | def any( | 814 | | - a: ArrayLike, | | 814 | + a: ArrayLike | None, | 815 | 815 | axis: int | tuple[int, ...] | None = None, | 816 | 816 | out: None = None, | 817 | 817 | keepdims: _Option[_nt.ToBool_0d] = ..., | @@ -820,7 +820,7 @@ def any( | 820 | 820 | ) -> np.bool | _nt.Array[np.bool]: ... | 821 | 821 | @overload | 822 | 822 | def any( | 823 | | - a: ArrayLike, | | 823 | + a: ArrayLike | None, | 824 | 824 | axis: int | tuple[int, ...] | None, | 825 | 825 | out: _ArrayT, | 826 | 826 | keepdims: _Option[_nt.ToBool_0d] = ..., | @@ -829,7 +829,7 @@ def any( | 829 | 829 | ) -> _ArrayT: ... | 830 | 830 | @overload | 831 | 831 | def any( | 832 | | - a: ArrayLike, | | 832 | + a: ArrayLike | None, | 833 | 833 | axis: int | tuple[int, ...] | None = None, | 834 | 834 | *, | 835 | 835 | out: _ArrayT, | |
Collapse file Copy file name to clipboard +9-11Lines changed: 9 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | from collections.abc import Callable, Iterable | 2 | | -from typing import Any, Final, NamedTuple | | 2 | +from typing import Any, Final, NamedTuple, TypeAlias | 3 | 3 | from typing_extensions import ParamSpec, TypeVar | 4 | 4 |
| 5 | | -from numpy._typing import _SupportsArrayFunc | 6 | | - | 7 | 5 | _T = TypeVar("_T") | 8 | 6 | _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]] | 10 | 10 |
| 11 | 11 | ### | 12 | 12 |
| @@ -20,12 +20,10 @@ class ArgSpec(NamedTuple): | 20 | 20 | defaults: tuple[Any, ...] | 21 | 21 |
| 22 | 22 | 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: ... | 24 | 24 |
| 25 | 25 | # | 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: ... | 29 | 27 |
| 30 | 28 | # NOTE: This actually returns a `_ArrayFunctionDispatcher` callable wrapper object, with | 31 | 29 | # the original wrapped callable stored in the `._implementation` attribute. It checks | @@ -38,16 +36,16 @@ def verify_matching_signatures( | 38 | 36 | # implement, ignoring the many hours that I and other stub maintainers are now losing | 39 | 37 | # because of this completely unreasonable restriction). | 40 | 38 | def array_function_dispatch( | 41 | | - dispatcher: Callable[_Tss, Iterable[_SupportsArrayFunc]] | None = None, | | 39 | + dispatcher: _Dispatcher[_Tss] | None = None, | 42 | 40 | module: str | None = None, | 43 | 41 | verify: bool = True, | 44 | 42 | docs_from_dispatcher: bool = False, | 45 | | -) -> Callable[[_FuncT], _FuncT]: ... | | 43 | +) -> Callable[[_FuncLikeT], _FuncLikeT]: ... | 46 | 44 |
| 47 | 45 | # | 48 | 46 | def array_function_from_dispatcher( | 49 | 47 | implementation: Callable[_Tss, _T], | 50 | 48 | module: str | None = None, | 51 | 49 | verify: bool = True, | 52 | 50 | docs_from_dispatcher: bool = True, | 53 | | -) -> Callable[[Callable[_Tss, Iterable[_SupportsArrayFunc]]], Callable[_Tss, _T]]: ... | | 51 | +) -> Callable[[_Dispatcher[_Tss]], Callable[_Tss, _T]]: ... |
Collapse file Copy file name to clipboardExpand all lines: src/numpy-stubs/lib/_iotools.pyi +10-6Lines changed: 10 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -from collections.abc import Callable, Iterable | | 1 | +from collections.abc import Callable, Iterable, Sequence | 2 | 2 | from typing import Any, ClassVar, Final, Literal as L, TypedDict, overload, type_check_only | 3 | 3 | from typing_extensions import TypeVar, Unpack | 4 | 4 |
| 5 | 5 | import numpy as np | 6 | 6 | import numpy.typing as npt | | 7 | +from numpy._typing._dtype_like import _DTypeLikeNested | 7 | 8 |
| 8 | 9 | _T = TypeVar("_T") | 9 | 10 |
| 10 | 11 | @type_check_only | 11 | | -class _ValidationKwargs(TypedDict, total=False): | | 12 | +class _NameValidatorKwargs(TypedDict, total=False): | 12 | 13 | excludelist: Iterable[str] | None | 13 | 14 | deletechars: Iterable[str] | None | 14 | 15 | case_sensitive: L["upper", "lower"] | bool | None | 15 | 16 | replace_space: str | 16 | 17 |
| 17 | 18 | ### | 18 | 19 |
| 19 | | -__docformat__: Final[str] = "restructuredtext en" | | 20 | +__docformat__: Final = "restructuredtext en" | 20 | 21 |
| 21 | 22 | class ConverterError(Exception): ... | 22 | 23 | class ConverterLockError(ConverterError): ... | @@ -94,6 +95,9 @@ class StringConverter: | 94 | 95 | @classmethod | 95 | 96 | def upgrade_mapper(cls, func: Callable[[str], Any], default: object | None = None) -> None: ... | 96 | 97 |
| | 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: ... | 97 | 101 | @overload | 98 | 102 | def str2bool(value: L["false", "False", "FALSE"]) -> L[False]: ... | 99 | 103 | @overload | @@ -109,8 +113,8 @@ def flatten_dtype( | 109 | 113 |
| 110 | 114 | # | 111 | 115 | 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, | 114 | 118 | defaultfmt: str = "f%i", | 115 | | - **validationargs: Unpack[_ValidationKwargs], | | 119 | + **validationargs: Unpack[_NameValidatorKwargs], | 116 | 120 | ) -> np.dtype[np.void]: ... |
|