From 4142f0003702144ef3d949fc6ba728a068227120 Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 4 Mar 2025 11:34:46 +0100 Subject: [PATCH 1/9] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20stub=20`numpy.=5Fco?= =?UTF-8?q?re.=5Fadd=5Fnewdocs=5Fscalars`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/numpy-stubs/_core/_add_newdocs_scalars.pyi | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/numpy-stubs/_core/_add_newdocs_scalars.pyi diff --git a/src/numpy-stubs/_core/_add_newdocs_scalars.pyi b/src/numpy-stubs/_core/_add_newdocs_scalars.pyi new file mode 100644 index 00000000..4a06c9b0 --- /dev/null +++ b/src/numpy-stubs/_core/_add_newdocs_scalars.pyi @@ -0,0 +1,16 @@ +from collections.abc import Iterable +from typing import Final + +import numpy as np + +possible_aliases: Final[list[tuple[type[np.number], str, str]]] = ... +_system: Final[str] = ... +_machine: Final[str] = ... +_doc_alias_string: Final[str] = ... +_bool_docstring: Final[str] = ... +int_name: str = ... +float_name: str = ... + +def numeric_type_aliases(aliases: list[tuple[str, str]]) -> list[tuple[type[np.number], str, str]]: ... +def add_newdoc_for_scalar_type(obj: str, fixed_aliases: Iterable[str], doc: str) -> None: ... +def _get_platform_and_machine() -> tuple[str, str]: ... From 87adcda3a4490cef5ef838867faf7c2d245285a6 Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 4 Mar 2025 11:34:57 +0100 Subject: [PATCH 2/9] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20stub=20`numpy.=5Fco?= =?UTF-8?q?re.=5Fadd=5Fnewdocs`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/numpy-stubs/_core/_add_newdocs.pyi | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/numpy-stubs/_core/_add_newdocs.pyi diff --git a/src/numpy-stubs/_core/_add_newdocs.pyi b/src/numpy-stubs/_core/_add_newdocs.pyi new file mode 100644 index 00000000..758bafbb --- /dev/null +++ b/src/numpy-stubs/_core/_add_newdocs.pyi @@ -0,0 +1,3 @@ +from numpy._core.overrides import get_array_function_like_doc as get_array_function_like_doc + +def refer_to_array_attribute(attr: str, method: bool = True) -> tuple[str, str]: ... From d6e1961ece0f85b1a9f57d40cab425bd5b5ae9f0 Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 4 Mar 2025 11:35:07 +0100 Subject: [PATCH 3/9] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20stub=20`numpy.=5Fco?= =?UTF-8?q?re.=5Fexceptions`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/numpy-stubs/_core/_exceptions.pyi | 72 +++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/numpy-stubs/_core/_exceptions.pyi diff --git a/src/numpy-stubs/_core/_exceptions.pyi b/src/numpy-stubs/_core/_exceptions.pyi new file mode 100644 index 00000000..f979e359 --- /dev/null +++ b/src/numpy-stubs/_core/_exceptions.pyi @@ -0,0 +1,72 @@ +from collections.abc import Iterable +from typing import Any, Final, overload +from typing_extensions import TypeVar, Unpack + +import numpy as np +from numpy import _CastingKind # noqa: ICN003 +from numpy._utils import set_module as set_module + +### + +_T = TypeVar("_T") +_TupleT = TypeVar("_TupleT", bound=tuple[()] | tuple[Any, Any, Unpack[tuple[Any, ...]]]) +_ExceptionT = TypeVar("_ExceptionT", bound=Exception) + +### + +class UFuncTypeError(TypeError): + ufunc: Final[np.ufunc] + def __init__(self, /, ufunc: np.ufunc) -> None: ... + +class _UFuncNoLoopError(UFuncTypeError): + dtypes: tuple[np.dtype[Any], ...] + def __init__(self, /, ufunc: np.ufunc, dtypes: Iterable[np.dtype[Any]]) -> None: ... + +class _UFuncBinaryResolutionError(_UFuncNoLoopError): + dtypes: tuple[np.dtype[Any], np.dtype[Any]] + def __init__(self, /, ufunc: np.ufunc, dtypes: Iterable[np.dtype[Any]]) -> None: ... + +class _UFuncCastingError(UFuncTypeError): + casting: Final[_CastingKind] + from_: Final[np.dtype[Any]] + to: Final[np.dtype[Any]] + def __init__(self, /, ufunc: np.ufunc, casting: _CastingKind, from_: np.dtype[Any], to: np.dtype[Any]) -> None: ... + +class _UFuncInputCastingError(_UFuncCastingError): + in_i: Final[int] + def __init__( + self, + /, + ufunc: np.ufunc, + casting: _CastingKind, + from_: np.dtype[Any], + to: np.dtype[Any], + i: int, + ) -> None: ... + +class _UFuncOutputCastingError(_UFuncCastingError): + out_i: Final[int] + def __init__( + self, + /, + ufunc: np.ufunc, + casting: _CastingKind, + from_: np.dtype[Any], + to: np.dtype[Any], + i: int, + ) -> None: ... + +class _ArrayMemoryError(MemoryError): + shape: tuple[int, ...] + dtype: np.dtype[Any] + def __init__(self, /, shape: tuple[int, ...], dtype: np.dtype[Any]) -> None: ... + @property + def _total_size(self) -> int: ... + @staticmethod + def _size_to_string(num_bytes: int) -> str: ... + +@overload +def _unpack_tuple(tup: tuple[_T]) -> _T: ... +@overload +def _unpack_tuple(tup: _TupleT) -> _TupleT: ... +def _display_as_base(cls: type[_ExceptionT]) -> type[_ExceptionT]: ... From 2d54baf63d7112d477c1b22ac28b6642a70e994e Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 4 Mar 2025 11:35:19 +0100 Subject: [PATCH 4/9] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20stub=20`numpy.=5Fco?= =?UTF-8?q?re.=5Fmachar`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/numpy-stubs/_core/_machar.pyi | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/numpy-stubs/_core/_machar.pyi diff --git a/src/numpy-stubs/_core/_machar.pyi b/src/numpy-stubs/_core/_machar.pyi new file mode 100644 index 00000000..392ca10b --- /dev/null +++ b/src/numpy-stubs/_core/_machar.pyi @@ -0,0 +1,38 @@ +from collections.abc import Callable +from typing_extensions import deprecated + +__all__ = ["MachAr"] + +@deprecated("deprecated in numpy 1.22") +class MachAr: + ibeta: int + it: int + machep: int + eps: float + negep: int + epsneg: float + iexp: int + minexp: int + xmin: float + maxexp: int + xmax: float + irnd: int + ngrd: int + epsilon: float + tiny: float + huge: float + precision: float + resolution: float + smallest_normal: float + smallest_subnormal: float + title: str | None + + def __init__( + self, + /, + float_conv: Callable[[int], float] = ..., + int_conv: Callable[[float], int] = ..., + float_to_float: Callable[[float], float] = ..., + float_to_str: Callable[[float], str] = ..., + title: str = "Python floating point number", + ) -> None: ... From 8c6e5bf920045c3e4a1e6807719d2a49e70fcd66 Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 4 Mar 2025 11:35:46 +0100 Subject: [PATCH 5/9] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20stub=20`numpy.=5Fco?= =?UTF-8?q?re.printoptions`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/numpy-stubs/_core/printoptions.pyi | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/numpy-stubs/_core/printoptions.pyi diff --git a/src/numpy-stubs/_core/printoptions.pyi b/src/numpy-stubs/_core/printoptions.pyi new file mode 100644 index 00000000..bd7c7b40 --- /dev/null +++ b/src/numpy-stubs/_core/printoptions.pyi @@ -0,0 +1,28 @@ +from collections.abc import Callable +from contextvars import ContextVar +from typing import Any, Final, TypedDict + +from .arrayprint import _FormatDict + +__all__ = ["format_options"] + +### + +class _FormatOptionsDict(TypedDict): + edgeitems: int + threshold: int + floatmode: str + precision: int + suppress: bool + linewidth: int + nanstr: str + infstr: str + sign: str + formatter: _FormatDict | None + legacy: int + override_repr: Callable[[Any], str] | None + +### + +default_format_options_dict: Final[_FormatOptionsDict] = ... +format_options: ContextVar[_FormatOptionsDict] From f2cd3e7f13547e65fa8dda048cc3fed631d76138 Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 4 Mar 2025 11:36:41 +0100 Subject: [PATCH 6/9] =?UTF-8?q?=F0=9F=99=88=20ignore=20missing=20`numpy.?= =?UTF-8?q?=5Fcore.cversions`=20module=20stubs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .mypyignore | 3 +++ .mypyignore-todo | 6 +----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.mypyignore b/.mypyignore index a4369900..1578536b 100644 --- a/.mypyignore +++ b/.mypyignore @@ -22,6 +22,9 @@ numpy\._core\.numeric\.__all__ numpy\._core\.numerictypes\.__all__ numpy\.matlib\.__all__ +# requires numpy/_core/code_generators to be on the PYTHONPATH when running stubtest +numpy\._core\.cversions + # workaround mypy's lack of Python 3.13 support for `NamedTuple` types (mypy <= 1.15.0) numpy\._core\.overrides\.ArgSpec\.__replace__ numpy\._utils\._pep440\._Version\.__replace__ diff --git a/.mypyignore-todo b/.mypyignore-todo index 31c1e353..5628758d 100644 --- a/.mypyignore-todo +++ b/.mypyignore-todo @@ -11,15 +11,11 @@ numpy(\..+)?\.complexfloating.__complex__ numpy(\.lib\._nanfunctions_impl|\.matlib)?\.nan(median|percentile) numpy(\.lib\._twodim_base_impl)?\.tri(l|u) +numpy\._core(\._multiarray_umath|\.multiarray)\.error numpy(\._core(\.memmap)?|\.matlib)?\.memmap\.__new__ numpy(\.matrixlib(\.defmatrix)?|\.matlib)?\.matrix\.__new__ numpy(\.lib\._polynomial_impl|\.matlib)?\.poly1d\.integ -numpy._core.cversions -numpy._core.printoptions - -numpy\._core(\._multiarray_umath|\.multiarray)\.error - numpy._core._type_aliases.is_complex numpy._core._type_aliases.full_name numpy._core._type_aliases.abstract_type From 5881cb89ae685a80aa36f161ec183c077de4d52b Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 4 Mar 2025 11:37:06 +0100 Subject: [PATCH 7/9] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20stub=20`numpy.=5Fco?= =?UTF-8?q?re.=5Fstring=5Fhelpers`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/numpy-stubs/_core/_string_helpers.pyi | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/numpy-stubs/_core/_string_helpers.pyi diff --git a/src/numpy-stubs/_core/_string_helpers.pyi b/src/numpy-stubs/_core/_string_helpers.pyi new file mode 100644 index 00000000..6a85832b --- /dev/null +++ b/src/numpy-stubs/_core/_string_helpers.pyi @@ -0,0 +1,12 @@ +from typing import Final + +_all_chars: Final[tuple[str, ...]] = ... +_ascii_upper: Final[tuple[str, ...]] = ... +_ascii_lower: Final[tuple[str, ...]] = ... + +LOWER_TABLE: Final[tuple[str, ...]] = ... +UPPER_TABLE: Final[tuple[str, ...]] = ... + +def english_lower(s: str) -> str: ... +def english_upper(s: str) -> str: ... +def english_capitalize(s: str) -> str: ... From 881d5742b2be5f9807935bc2a7eef9fe5edc824c Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 4 Mar 2025 11:49:00 +0100 Subject: [PATCH 8/9] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20stub=20`numpy.=5Fco?= =?UTF-8?q?re.=5Fsimd`=20(the=20module,=20not=20the=20package)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/numpy-stubs/_core/_simd.pyi | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/numpy-stubs/_core/_simd.pyi diff --git a/src/numpy-stubs/_core/_simd.pyi b/src/numpy-stubs/_core/_simd.pyi new file mode 100644 index 00000000..011448ac --- /dev/null +++ b/src/numpy-stubs/_core/_simd.pyi @@ -0,0 +1,14 @@ +from types import ModuleType + +SSE42: ModuleType | None = ... +AVX2: ModuleType | None = ... +FMA3: ModuleType | None = ... +AVX512F: ModuleType | None = ... +AVX512_SKX: ModuleType | None = ... +baseline: ModuleType | None = ... + +# TODO(jorenham): TypedDict +targets: dict[str, ModuleType | None] = ... + +def clear_floatstatus() -> None: ... +def get_floatstatus() -> int: ... From bb92875e0c8d7f124050dea576f796bce4829e58 Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 4 Mar 2025 11:49:10 +0100 Subject: [PATCH 9/9] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20stub=20`numpy.=5Fco?= =?UTF-8?q?re.=5Fmethods`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/numpy-stubs/_core/_methods.pyi | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/numpy-stubs/_core/_methods.pyi diff --git a/src/numpy-stubs/_core/_methods.pyi b/src/numpy-stubs/_core/_methods.pyi new file mode 100644 index 00000000..65fec9ed --- /dev/null +++ b/src/numpy-stubs/_core/_methods.pyi @@ -0,0 +1,14 @@ +import numpy as np +from numpy._typing._ufunc import _Reduce2 + +from . import _exceptions as _exceptions, umath as um + +bool_dt: np.dtype[np.bool] = ... +umr_maximum: _Reduce2 = ... +umr_minimum: _Reduce2 = ... +umr_sum: _Reduce2 = ... +umr_prod: _Reduce2 = ... +umr_bitwise_count = um.bitwise_count +umr_any: _Reduce2 = ... +umr_all: _Reduce2 = ... +_complex_to_float: dict[np.dtype[np.complexfloating], np.dtype[np.floating]] = ...