Skip to content

Commit 2865629

Browse files
authored
Merge pull request #763 from numpy/np24/_core
2 parents 6f9b7fa + 433fe84 commit 2865629

File tree

17 files changed

+96
-338
lines changed

17 files changed

+96
-338
lines changed

src/numpy-stubs/@test/static/accept/getlimits.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ assert_type(np.finfo(c8), np.finfo[np.float32])
1919
assert_type(np.finfo("f2"), np.finfo[np.float16])
2020

2121
assert_type(finfo_f8.dtype, np.dtype[np.float64])
22-
assert_type(finfo_f8.bits, Literal[2, 4, 8, 12, 16])
22+
assert_type(finfo_f8.bits, int)
2323
assert_type(finfo_f8.eps, np.float64)
2424
assert_type(finfo_f8.epsneg, np.float64)
2525
assert_type(finfo_f8.iexp, int)

src/numpy-stubs/@test/static/reject/arrayprint.pyi

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/numpy-stubs/@test/static/reject/ndarray_misc.pyi

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ ctypes_obj = AR_f8.ctypes
1515

1616
###
1717

18-
ctypes_obj.get_data() # pyright: ignore[reportDeprecated]
19-
ctypes_obj.get_shape() # pyright: ignore[reportDeprecated]
20-
ctypes_obj.get_strides() # pyright: ignore[reportDeprecated]
21-
ctypes_obj.get_as_parameter() # pyright: ignore[reportDeprecated]
22-
2318
# NOTE: mypy stops analysis after something returns `NoReturn`; wrapping them in functions works around this
2419

2520
def test_argpartition() -> None:
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
from numpy._core.overrides import get_array_function_like_doc as get_array_function_like_doc
2-
3-
def refer_to_array_attribute(attr: str, method: bool = True) -> tuple[str, str]: ...
1+
from .function_base import add_newdoc as add_newdoc
2+
from .overrides import get_array_function_like_doc as get_array_function_like_doc
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from collections.abc import Iterable
21
from typing import Final
32

43
import numpy as np
@@ -8,9 +7,10 @@ _system: Final[str] = ...
87
_machine: Final[str] = ...
98
_doc_alias_string: Final[str] = ...
109
_bool_docstring: Final[str] = ...
10+
bool_name: str = ...
1111
int_name: str = ...
1212
float_name: str = ...
1313

1414
def numeric_type_aliases(aliases: list[tuple[str, str]]) -> list[tuple[type[np.number], str, str]]: ...
15-
def add_newdoc_for_scalar_type(obj: str, fixed_aliases: Iterable[str], doc: str) -> None: ...
15+
def add_newdoc_for_scalar_type(name: str, text_signature: str, doc: str) -> None: ...
1616
def _get_platform_and_machine() -> tuple[str, str]: ...

src/numpy-stubs/_core/_internal.pyi

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ctypes as ct
22
import re
33
from collections.abc import Callable, Iterable
44
from typing import Final, Generic, Self, overload
5-
from typing_extensions import TypeVar, deprecated, override
5+
from typing_extensions import TypeVar, override
66

77
import _numtype as _nt
88
import numpy as np
@@ -49,16 +49,6 @@ class _ctypes(Generic[_PT_co]):
4949
def shape_as(self, /, obj: type[_CT]) -> ct.Array[_CT]: ...
5050
def strides_as(self, /, obj: type[_CT]) -> ct.Array[_CT]: ...
5151

52-
#
53-
@deprecated('"get_data" is deprecated. Use "data" instead')
54-
def get_data(self, /) -> _PT_co: ...
55-
@deprecated('"get_shape" is deprecated. Use "shape" instead')
56-
def get_shape(self, /) -> ct.Array[c_intp]: ...
57-
@deprecated('"get_strides" is deprecated. Use "strides" instead')
58-
def get_strides(self, /) -> ct.Array[c_intp]: ...
59-
@deprecated('"get_as_parameter" is deprecated. Use "_as_parameter_" instead')
60-
def get_as_parameter(self, /) -> ct.c_void_p: ...
61-
6252
class dummy_ctype(Generic[_T_co]):
6353
_cls: type[_T_co]
6454

src/numpy-stubs/_core/_machar.pyi

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/numpy-stubs/_core/_methods.pyi

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1+
from collections.abc import Callable
2+
from typing import Any, Concatenate, TypeAlias
3+
14
import numpy as np
2-
from numpy._core.umath import _Reduce2
35

4-
from . import _exceptions as _exceptions, umath as um
6+
from . import _exceptions as _exceptions
7+
8+
###
9+
10+
_Reduce2: TypeAlias = Callable[Concatenate[object, ...], Any]
11+
12+
###
513

614
bool_dt: np.dtype[np.bool] = ...
715
umr_maximum: _Reduce2 = ...
816
umr_minimum: _Reduce2 = ...
917
umr_sum: _Reduce2 = ...
1018
umr_prod: _Reduce2 = ...
11-
umr_bitwise_count = um.bitwise_count
19+
umr_bitwise_count = np.bitwise_count
1220
umr_any: _Reduce2 = ...
1321
umr_all: _Reduce2 = ...
1422
_complex_to_float: dict[np.dtype[np.complexfloating], np.dtype[np.floating]] = ...

src/numpy-stubs/_core/_type_aliases.pyi

Lines changed: 33 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,37 @@ from typing import Final, Literal as L, TypeAlias, TypedDict, type_check_only
33

44
import numpy as np
55

6-
###
6+
sctypeDict: Final[dict[str, type[np.generic]]] = ...
7+
allTypes: Final[dict[str, type[np.generic]]] = ...
78

89
@type_check_only
910
class _CNamesDict(TypedDict):
10-
BOOL: np.dtypes.BoolDType
11-
BYTE: np.dtypes.ByteDType
12-
UBYTE: np.dtypes.UByteDType
13-
SHORT: np.dtypes.ShortDType
14-
USHORT: np.dtypes.UShortDType
15-
INT: np.dtypes.IntDType
16-
UINT: np.dtypes.UIntDType
17-
LONG: np.dtypes.LongDType
18-
ULONG: np.dtypes.ULongDType
19-
LONGLONG: np.dtypes.LongLongDType
20-
ULONGLONG: np.dtypes.ULongLongDType
21-
HALF: np.dtypes.Float16DType
22-
FLOAT: np.dtypes.Float32DType
23-
DOUBLE: np.dtypes.Float64DType
24-
LONGDOUBLE: np.dtypes.LongDoubleDType
25-
CFLOAT: np.dtypes.Complex64DType
26-
CDOUBLE: np.dtypes.Complex128DType
27-
CLONGDOUBLE: np.dtypes.CLongDoubleDType
28-
STRING: np.dtypes.BytesDType
29-
UNICODE: np.dtypes.StrDType
30-
VOID: np.dtypes.VoidDType
31-
OBJECT: np.dtypes.ObjectDType
32-
DATETIME: np.dtypes.DateTime64DType
33-
TIMEDELTA: np.dtypes.TimeDelta64DType
11+
BOOL: np.dtype[np.bool]
12+
HALF: np.dtype[np.half]
13+
FLOAT: np.dtype[np.single]
14+
DOUBLE: np.dtype[np.double]
15+
LONGDOUBLE: np.dtype[np.longdouble]
16+
CFLOAT: np.dtype[np.csingle]
17+
CDOUBLE: np.dtype[np.cdouble]
18+
CLONGDOUBLE: np.dtype[np.clongdouble]
19+
STRING: np.dtype[np.bytes_]
20+
UNICODE: np.dtype[np.str_]
21+
VOID: np.dtype[np.void]
22+
OBJECT: np.dtype[np.object_]
23+
DATETIME: np.dtype[np.datetime64]
24+
TIMEDELTA: np.dtype[np.timedelta64]
25+
BYTE: np.dtype[np.byte]
26+
UBYTE: np.dtype[np.ubyte]
27+
SHORT: np.dtype[np.short]
28+
USHORT: np.dtype[np.ushort]
29+
INT: np.dtype[np.intc]
30+
UINT: np.dtype[np.uintc]
31+
LONG: np.dtype[np.long]
32+
ULONG: np.dtype[np.ulong]
33+
LONGLONG: np.dtype[np.longlong]
34+
ULONGLONG: np.dtype[np.ulonglong]
35+
36+
c_names_dict: Final[_CNamesDict] = ...
3437

3538
_AbstractTypeName: TypeAlias = L[
3639
"generic",
@@ -44,6 +47,7 @@ _AbstractTypeName: TypeAlias = L[
4447
"floating",
4548
"complexfloating",
4649
]
50+
_abstract_type_names: Final[set[_AbstractTypeName]] = ...
4751

4852
@type_check_only
4953
class _AliasesType(TypedDict):
@@ -56,6 +60,8 @@ class _AliasesType(TypedDict):
5660
int_: L["intp"]
5761
uint: L["intp"]
5862

63+
_aliases: Final[_AliasesType] = ...
64+
5965
@type_check_only
6066
class _ExtraAliasesType(TypedDict):
6167
float: L["float64"]
@@ -67,6 +73,8 @@ class _ExtraAliasesType(TypedDict):
6773
str: L["str_"]
6874
unicode: L["str_"]
6975

76+
_extra_aliases: Final[_ExtraAliasesType] = ...
77+
7078
@type_check_only
7179
class _SCTypes(TypedDict):
7280
int: Collection[type[np.signedinteger]]
@@ -75,29 +83,4 @@ class _SCTypes(TypedDict):
7583
complex: Collection[type[np.complexfloating]]
7684
others: Collection[type[np.flexible | np.bool | np.object_]]
7785

78-
###
79-
80-
sctypeDict: Final[dict[str, type[np.generic]]] = ...
81-
allTypes: Final[dict[str, type[np.generic]]] = ...
82-
c_names_dict: Final[_CNamesDict] = ...
8386
sctypes: Final[_SCTypes] = ...
84-
85-
_abstract_type_names: Final[set[_AbstractTypeName]] = ...
86-
_aliases: Final[_AliasesType] = ...
87-
_extra_aliases: Final[_ExtraAliasesType] = ...
88-
89-
# namespace pollution
90-
k: str
91-
v: str
92-
is_complex: bool
93-
full_name: str
94-
longdouble_type: type[np.longdouble | np.clongdouble]
95-
bits: int
96-
base_name: str
97-
extended_prec_name: str
98-
type_info: np.dtype
99-
type_group: str
100-
concrete_type: type[np.generic]
101-
abstract_type: type[np.generic]
102-
sctype_key: str
103-
sctype_list: list[type[np.generic]]

src/numpy-stubs/_core/arrayprint.pyi

Lines changed: 2 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
from collections.abc import Callable
22
from contextlib import _GeneratorContextManager
3-
from typing import Final, Literal, SupportsIndex, TypeAlias, TypedDict, overload, type_check_only
4-
from typing_extensions import deprecated
3+
from typing import Final, Literal, SupportsIndex, TypeAlias, TypedDict, type_check_only
54

65
import _numtype as _nt
76
import numpy as np
8-
from numpy._globals import _NoValueType
97
from numpy._typing import _CharLike_co, _FloatLike_co
108

119
__all__ = [
@@ -25,7 +23,6 @@ _FloatMode: TypeAlias = Literal["fixed", "unique", "maxprec", "maxprec_equal"]
2523
_Sign: TypeAlias = Literal["-", "+", " "]
2624
_Trim: TypeAlias = Literal["k", ".", "0", "-"]
2725
_Legacy: TypeAlias = Literal["1.13", "1.21", "1.25", "2.1", False]
28-
_LegacyNoStyle: TypeAlias = Literal["1.21", "1.25", "2.1", False]
2926
_ReprFunc: TypeAlias = Callable[[_nt.Array], str]
3027

3128
@type_check_only
@@ -103,43 +100,6 @@ def printoptions(
103100
) -> _GeneratorContextManager[_FormatOptions]: ...
104101

105102
# public numpy export
106-
@overload # no style
107-
def array2string(
108-
a: _nt.Array,
109-
max_line_width: int | None = None,
110-
precision: SupportsIndex | None = None,
111-
suppress_small: bool | None = None,
112-
separator: str = " ",
113-
prefix: str = "",
114-
style: _NoValueType = ...,
115-
formatter: _FormatDict | None = None,
116-
threshold: int | None = None,
117-
edgeitems: int | None = None,
118-
sign: _Sign | None = None,
119-
floatmode: _FloatMode | None = None,
120-
suffix: str = "",
121-
*,
122-
legacy: _Legacy | None = None,
123-
) -> str: ...
124-
@overload # style=<given> (positional), legacy="1.13"
125-
def array2string(
126-
a: _nt.Array,
127-
max_line_width: int | None,
128-
precision: SupportsIndex | None,
129-
suppress_small: bool | None,
130-
separator: str,
131-
prefix: str,
132-
style: _ReprFunc,
133-
formatter: _FormatDict | None = None,
134-
threshold: int | None = None,
135-
edgeitems: int | None = None,
136-
sign: _Sign | None = None,
137-
floatmode: _FloatMode | None = None,
138-
suffix: str = "",
139-
*,
140-
legacy: Literal["1.13"],
141-
) -> str: ...
142-
@overload # style=<given> (keyword), legacy="1.13"
143103
def array2string(
144104
a: _nt.Array,
145105
max_line_width: int | None = None,
@@ -148,52 +108,13 @@ def array2string(
148108
separator: str = " ",
149109
prefix: str = "",
150110
*,
151-
style: _ReprFunc,
152111
formatter: _FormatDict | None = None,
153112
threshold: int | None = None,
154113
edgeitems: int | None = None,
155114
sign: _Sign | None = None,
156115
floatmode: _FloatMode | None = None,
157116
suffix: str = "",
158-
legacy: Literal["1.13"],
159-
) -> str: ...
160-
@overload # style=<given> (positional), legacy!="1.13"
161-
@deprecated("'style' argument is deprecated and no longer functional except in 1.13 'legacy' mode")
162-
def array2string(
163-
a: _nt.Array,
164-
max_line_width: int | None,
165-
precision: SupportsIndex | None,
166-
suppress_small: bool | None,
167-
separator: str,
168-
prefix: str,
169-
style: _ReprFunc,
170-
formatter: _FormatDict | None = None,
171-
threshold: int | None = None,
172-
edgeitems: int | None = None,
173-
sign: _Sign | None = None,
174-
floatmode: _FloatMode | None = None,
175-
suffix: str = "",
176-
*,
177-
legacy: _LegacyNoStyle | None = None,
178-
) -> str: ...
179-
@overload # style=<given> (keyword), legacy="1.13"
180-
@deprecated("'style' argument is deprecated and no longer functional except in 1.13 'legacy' mode")
181-
def array2string(
182-
a: _nt.Array,
183-
max_line_width: int | None = None,
184-
precision: SupportsIndex | None = None,
185-
suppress_small: bool | None = None,
186-
separator: str = " ",
187-
prefix: str = "",
188-
*,
189-
style: _ReprFunc,
190-
formatter: _FormatDict | None = None,
191-
threshold: int | None = None,
192-
edgeitems: int | None = None,
193-
sign: _Sign | None = None,
194-
floatmode: _FloatMode | None = None,
195-
suffix: str = "",
196-
legacy: _LegacyNoStyle | None = None,
117+
legacy: _Legacy | None = None,
197118
) -> str: ...
198119

199120
# public numpy export

0 commit comments

Comments
 (0)