Skip to content

Commit 8254e64

Browse files
authored
Merge pull request #548 from numpy/prefer-_nt.Array
2 parents cd48b3d + 8887412 commit 8254e64

File tree

16 files changed

+992
-941
lines changed

16 files changed

+992
-941
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
from typing import TypeAlias, assert_type
1+
from typing import Any, TypeAlias, assert_type
2+
from typing_extensions import TypeVar
23

34
import _numtype as _nt
45
import numpy as np
56

6-
_BytesArray: TypeAlias = np.char.chararray[_nt.Shape, np.dtype[np.bytes_]]
7-
_StrArray: TypeAlias = np.char.chararray[_nt.Shape, np.dtype[np.str_]]
7+
_ShapeT = TypeVar("_ShapeT", bound=_nt.Shape, default=_nt.Shape)
8+
9+
_BytesArray: TypeAlias = np.char.chararray[_ShapeT, np.dtype[np.bytes_]]
10+
_StrArray: TypeAlias = np.char.chararray[_ShapeT, np.dtype[np.str_]]
11+
12+
###
813

914
AR_U: _StrArray
1015
AR_S: _BytesArray
@@ -85,8 +90,8 @@ assert_type(AR_S.title(), _BytesArray)
8590
assert_type(AR_U.upper(), _StrArray)
8691
assert_type(AR_S.upper(), _BytesArray)
8792

88-
assert_type(AR_U.zfill(5), _StrArray)
89-
assert_type(AR_S.zfill([2, 3, 4]), _BytesArray)
93+
assert_type(AR_U.zfill(5), _StrArray[Any])
94+
assert_type(AR_S.zfill([2, 3, 4]), _BytesArray[Any])
9095

9196
assert_type(AR_U.count("a", start=[1, 2, 3]), _nt.Array[np.int_])
9297
assert_type(AR_S.count([b"a", b"b", b"c"], end=9), _nt.Array[np.int_])

src/numpy-stubs/__init__.pyi

Lines changed: 436 additions & 418 deletions
Large diffs are not rendered by default.

src/numpy-stubs/_core/arrayprint.pyi

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from collections.abc import Callable
22
from contextlib import _GeneratorContextManager
3-
from typing import Any, Final, Literal, SupportsIndex, TypeAlias, TypedDict, overload, type_check_only
3+
from typing import Final, Literal, SupportsIndex, TypeAlias, TypedDict, overload, type_check_only
44
from typing_extensions import deprecated
55

6+
import _numtype as _nt
67
import numpy as np
78
from numpy._globals import _NoValueType
8-
from numpy._typing import NDArray, _CharLike_co, _FloatLike_co
9+
from numpy._typing import _CharLike_co, _FloatLike_co
910

1011
__all__ = [
1112
"array2string",
@@ -25,7 +26,7 @@ _Sign: TypeAlias = Literal["-", "+", " "]
2526
_Trim: TypeAlias = Literal["k", ".", "0", "-"]
2627
_Legacy: TypeAlias = Literal["1.13", "1.21", "1.25", "2.1", False]
2728
_LegacyNoStyle: TypeAlias = Literal["1.21", "1.25", "2.1", False]
28-
_ReprFunc: TypeAlias = Callable[[NDArray[Any]], str]
29+
_ReprFunc: TypeAlias = Callable[[_nt.Array], str]
2930

3031
@type_check_only
3132
class _FormatDict(TypedDict, total=False):
@@ -104,7 +105,7 @@ def printoptions(
104105
# public numpy export
105106
@overload # no style
106107
def array2string(
107-
a: NDArray[Any],
108+
a: _nt.Array,
108109
max_line_width: int | None = None,
109110
precision: SupportsIndex | None = None,
110111
suppress_small: bool | None = None,
@@ -122,7 +123,7 @@ def array2string(
122123
) -> str: ...
123124
@overload # style=<given> (positional), legacy="1.13"
124125
def array2string(
125-
a: NDArray[Any],
126+
a: _nt.Array,
126127
max_line_width: int | None,
127128
precision: SupportsIndex | None,
128129
suppress_small: bool | None,
@@ -140,7 +141,7 @@ def array2string(
140141
) -> str: ...
141142
@overload # style=<given> (keyword), legacy="1.13"
142143
def array2string(
143-
a: NDArray[Any],
144+
a: _nt.Array,
144145
max_line_width: int | None = None,
145146
precision: SupportsIndex | None = None,
146147
suppress_small: bool | None = None,
@@ -159,7 +160,7 @@ def array2string(
159160
@overload # style=<given> (positional), legacy!="1.13"
160161
@deprecated("'style' argument is deprecated and no longer functional except in 1.13 'legacy' mode")
161162
def array2string(
162-
a: NDArray[Any],
163+
a: _nt.Array,
163164
max_line_width: int | None,
164165
precision: SupportsIndex | None,
165166
suppress_small: bool | None,
@@ -178,7 +179,7 @@ def array2string(
178179
@overload # style=<given> (keyword), legacy="1.13"
179180
@deprecated("'style' argument is deprecated and no longer functional except in 1.13 'legacy' mode")
180181
def array2string(
181-
a: NDArray[Any],
182+
a: _nt.Array,
182183
max_line_width: int | None = None,
183184
precision: SupportsIndex | None = None,
184185
suppress_small: bool | None = None,
@@ -222,15 +223,15 @@ def format_float_positional(
222223

223224
# public numpy export
224225
def array_repr(
225-
arr: NDArray[Any],
226+
arr: _nt.Array,
226227
max_line_width: int | None = None,
227228
precision: SupportsIndex | None = None,
228229
suppress_small: bool | None = None,
229230
) -> str: ...
230231

231232
# public numpy export
232233
def array_str(
233-
a: NDArray[Any],
234+
a: _nt.Array,
234235
max_line_width: int | None = None,
235236
precision: SupportsIndex | None = None,
236237
suppress_small: bool | None = None,

0 commit comments

Comments
 (0)