Skip to content

Commit 142f8a2

Browse files
authored
🐛 fix import-related mypy errors (#9)
2 parents db68945 + 51b7966 commit 142f8a2

File tree

9 files changed

+254
-277
lines changed

9 files changed

+254
-277
lines changed

src/numpy-stubs/__init__.pyi

Lines changed: 192 additions & 185 deletions
Large diffs are not rendered by default.

src/numpy-stubs/_typing/_array_like.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
from collections.abc import Callable, Collection, Sequence
3-
from typing import Any, Never as _UnknownType, Protocol, TypeAlias, runtime_checkable
4-
from typing_extensions import TypeVar
3+
from typing import Any, Protocol, TypeAlias, runtime_checkable
4+
from typing_extensions import Never, TypeVar
55

66
import numpy as np
77
from numpy.dtypes import StringDType
@@ -23,6 +23,7 @@ _DType = TypeVar("_DType", bound=np.dtype[Any])
2323
_DType_co = TypeVar("_DType_co", covariant=True, bound=np.dtype[Any])
2424

2525
NDArray: TypeAlias = np.ndarray[_Shape, np.dtype[_ScalarType_co]]
26+
_UnknownType: TypeAlias = Never
2627

2728
# The `_SupportsArray` protocol only cares about the default dtype
2829
# (i.e. `dtype=None` or no `dtype` parameter at all) of the to-be returned

src/numpy-stubs/_typing/_callable.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class _IntTrueDiv(Protocol[_NBit1]):
111111
@overload
112112
def __call__(self, other: float, /) -> np.floating[_NBit1] | np.float64: ...
113113
@overload
114-
def __call__(self, other: complex, /) -> np.complexnp.floating[_NBit1] | np.complex128: ...
114+
def __call__(self, other: complex, /) -> np.complexfloating[_NBit1] | np.complex128: ...
115115
@overload
116116
def __call__(self, other: np.integer[_NBit2], /) -> np.floating[_NBit1] | np.floating[_NBit2]: ...
117117

src/numpy-stubs/lib/_format_impl.pyi

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

src/numpy-stubs/lib/_function_base_impl.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def interp(
299299
def interp(
300300
x: _FloatLike_co,
301301
xp: _ArrayLikeFloat_co,
302-
fp: Sequence[complex | np.ccomplexfloating],
302+
fp: Sequence[complex | np.complexfloating],
303303
left: _NumberLike_co | None = None,
304304
right: _NumberLike_co | None = None,
305305
period: _FloatLike_co | None = None,
Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
from numpy._core.fromnumeric import amax, amin, argmax, argmin, cumprod, cumsum, mean, prod, std, sum, var
2-
from numpy.lib._function_base_impl import (
3-
median,
4-
percentile,
5-
quantile,
1+
# NOTE: In reality these functions are not aliases but distinct functions with identical signatures.
2+
from numpy._core.fromnumeric import (
3+
amax as nanmax,
4+
amin as nanmin,
5+
argmax as nanargmax,
6+
argmin as nanargmin,
7+
cumprod as nancumprod,
8+
cumsum as nancumsum,
9+
mean as nanmean,
10+
prod as nanprod,
11+
std as nanstd,
12+
sum as nansum,
13+
var as nanvar,
614
)
15+
from numpy.lib._function_base_impl import median as nanmedian, percentile as nanpercentile, quantile as nanquantile
716

817
__all__ = [
918
"nanargmax",
@@ -21,20 +30,3 @@ __all__ = [
2130
"nansum",
2231
"nanvar",
2332
]
24-
25-
# NOTE: In reality these functions are not aliases but distinct functions
26-
# with identical signatures.
27-
nanmin = amin
28-
nanmax = amax
29-
nanargmin = argmin
30-
nanargmax = argmax
31-
nansum = sum
32-
nanprod = prod
33-
nancumsum = cumsum
34-
nancumprod = cumprod
35-
nanmean = mean
36-
nanvar = var
37-
nanstd = std
38-
nanmedian = median
39-
nanpercentile = percentile
40-
nanquantile = quantile

src/numpy-stubs/lib/_polynomial_impl.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ from numpy._typing import (
1717
_T = TypeVar("_T")
1818

1919
_2Tup: TypeAlias = tuple[_T, _T]
20-
_5Tup: TypeAlias = tuple[_T, NDArray[np.np.float64], NDArray[np.int32], NDArray[np.float64], NDArray[np.float64]]
20+
_5Tup: TypeAlias = tuple[_T, NDArray[np.float64], NDArray[np.int32], NDArray[np.float64], NDArray[np.float64]]
2121

2222
__all__ = ["poly", "poly1d", "polyadd", "polyder", "polydiv", "polyfit", "polyint", "polymul", "polysub", "polyval", "roots"]
2323

src/numpy-stubs/lib/_twodim_base_impl.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ def vander(x: _ArrayLikeComplex_co, N: int | None = ..., increasing: bool = ...)
137137
@overload
138138
def vander(x: _ArrayLikeObject_co, N: int | None = ..., increasing: bool = ...) -> NDArray[np.object_]: ...
139139

140-
_Int_co: TypeAlias = np.integer[Any] | np.bool
141-
_Float_co: TypeAlias = np.floating[Any] | _Int_co
142-
_Number_co: TypeAlias = np.np.number | np.bool
140+
_Int_co: TypeAlias = np.integer | np.bool
141+
_Float_co: TypeAlias = np.floating | _Int_co
142+
_Number_co: TypeAlias = np.number | np.bool
143143

144144
_ArrayLike1D: TypeAlias = _SupportsArray[np.dtype[_SCT]] | Sequence[_SCT]
145145
_ArrayLike2D: TypeAlias = _SupportsArray[np.dtype[_SCT]] | Sequence[_ArrayLike1D[_SCT]]

src/numpy-stubs/lib/format.pyi

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,39 @@
1-
from ._format_impl import (
2-
ARRAY_ALIGN as ARRAY_ALIGN,
3-
BUFFER_SIZE as BUFFER_SIZE,
4-
EXPECTED_KEYS as EXPECTED_KEYS,
5-
GROWTH_AXIS_MAX_DIGITS as GROWTH_AXIS_MAX_DIGITS,
6-
MAGIC_LEN as MAGIC_LEN,
7-
MAGIC_PREFIX as MAGIC_PREFIX,
8-
__all__ as __all__,
9-
__doc__ as __doc__,
10-
descr_to_dtype as descr_to_dtype,
11-
drop_metadata as drop_metadata,
12-
dtype_to_descr as dtype_to_descr,
13-
header_data_from_array_1_0 as header_data_from_array_1_0,
14-
isfileobj as isfileobj,
15-
magic as magic,
16-
open_memmap as open_memmap,
17-
read_array as read_array,
18-
read_array_header_1_0 as read_array_header_1_0,
19-
read_array_header_2_0 as read_array_header_2_0,
20-
read_magic as read_magic,
21-
write_array as write_array,
22-
write_array_header_1_0 as write_array_header_1_0,
23-
write_array_header_2_0 as write_array_header_2_0,
24-
)
1+
from _typeshed import Incomplete
2+
from typing import Final, Literal
3+
4+
__all__: list[str] = []
5+
6+
EXPECTED_KEYS: Final[set[str]]
7+
MAGIC_PREFIX: Final[bytes]
8+
MAGIC_LEN: Literal[8]
9+
ARRAY_ALIGN: Literal[64]
10+
BUFFER_SIZE: Literal[262144] # 2**18
11+
GROWTH_AXIS_MAX_DIGITS: Literal[21]
12+
13+
def magic(major: Incomplete, minor: Incomplete) -> Incomplete: ...
14+
def read_magic(fp: Incomplete) -> Incomplete: ...
15+
def dtype_to_descr(dtype: Incomplete) -> Incomplete: ...
16+
def descr_to_dtype(descr: Incomplete) -> Incomplete: ...
17+
def header_data_from_array_1_0(array: Incomplete) -> Incomplete: ...
18+
def write_array_header_1_0(fp: Incomplete, d: Incomplete) -> Incomplete: ...
19+
def write_array_header_2_0(fp: Incomplete, d: Incomplete) -> Incomplete: ...
20+
def read_array_header_1_0(fp: Incomplete) -> Incomplete: ...
21+
def read_array_header_2_0(fp: Incomplete) -> Incomplete: ...
22+
def write_array(
23+
fp: Incomplete,
24+
array: Incomplete,
25+
version: Incomplete = ...,
26+
allow_pickle: Incomplete = ...,
27+
pickle_kwargs: Incomplete = ...,
28+
) -> Incomplete: ...
29+
def read_array(fp: Incomplete, allow_pickle: Incomplete = ..., pickle_kwargs: Incomplete = ...) -> Incomplete: ...
30+
def open_memmap(
31+
filename: Incomplete,
32+
mode: Incomplete = ...,
33+
dtype: Incomplete = ...,
34+
shape: Incomplete = ...,
35+
fortran_order: Incomplete = ...,
36+
version: Incomplete = ...,
37+
) -> Incomplete: ...
38+
def isfileobj(f: Incomplete) -> Incomplete: ...
39+
def drop_metadata(dtype: Incomplete, /) -> Incomplete: ...

0 commit comments

Comments
 (0)