Skip to content

Commit da0ba80

Browse files
committed
🚨 fix PYI047 errors in numpy-stubs
1 parent 41379c6 commit da0ba80

File tree

10 files changed

+26
-110
lines changed

10 files changed

+26
-110
lines changed

‎src/numpy-stubs/__init__.pyi

Lines changed: 1 addition & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import sys
77
from _typeshed import Incomplete, StrOrBytesPath, SupportsFlush, SupportsLenAndGetItem, SupportsWrite
88
from builtins import bool as py_bool
99
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
10-
from decimal import Decimal
11-
from fractions import Fraction
1210
from types import EllipsisType, GenericAlias, GetSetDescriptorType, MappingProxyType, ModuleType
1311
from typing import (
1412
Any,
@@ -694,64 +692,6 @@ _SubModule: TypeAlias = L[
694692
"testing",
695693
"typing",
696694
]
697-
_ExpiredAttribute: TypeAlias = L[
698-
"DataSource",
699-
"Inf",
700-
"Infinity",
701-
"NINF",
702-
"NZERO",
703-
"NaN",
704-
"PINF",
705-
"PZERO",
706-
"add_docstring",
707-
"add_newdoc",
708-
"add_newdoc_ufunc",
709-
"alltrue",
710-
"asfarray",
711-
"byte_bounds",
712-
"cast",
713-
"cfloat",
714-
"clongfloat",
715-
"compare_chararrays",
716-
"compat",
717-
"complex_",
718-
"deprecate",
719-
"deprecate_with_doc",
720-
"disp",
721-
"fastCopyAndTranspose",
722-
"find_common_type",
723-
"float_",
724-
"format_parser",
725-
"get_array_wrap",
726-
"geterrobj",
727-
"infty",
728-
"issctype",
729-
"issubclass_",
730-
"issubsctype",
731-
"longcomplex",
732-
"longfloat",
733-
"lookfor",
734-
"mat",
735-
"maximum_sctype",
736-
"nbytes",
737-
"obj2sctype",
738-
"recfromcsv",
739-
"recfromtxt",
740-
"round_",
741-
"safe_eval",
742-
"sctype2char",
743-
"sctypes",
744-
"set_numeric_ops",
745-
"set_string_function",
746-
"seterrobj",
747-
"singlecomplex",
748-
"sometrue",
749-
"source",
750-
"string_",
751-
"tracemalloc_domain",
752-
"unicode_",
753-
"who",
754-
]
755695
_UFuncMethod: TypeAlias = L["__call__", "reduce", "reduceat", "accumulate", "outer", "at"]
756696

757697
_2Tuple: TypeAlias = tuple[_T, _T]
@@ -769,12 +709,10 @@ _JustBuiltinScalar: TypeAlias = int | _nt.JustFloat | _nt.JustComplex | _nt.Just
769709

770710
_AbstractInexact: TypeAlias = _JustInexact | _JustFloating | _JustComplexFloating
771711
_AbstractInteger: TypeAlias = _JustInteger | _JustSignedInteger | _JustUnsignedInteger
772-
_AbstractNumber: TypeAlias = _JustNumber | _AbstractInteger | _AbstractInexact
773712

774713
_int32_min: TypeAlias = int32 | int64
775714
_int16_min: TypeAlias = int16 | _int32_min
776715
_int16_max: TypeAlias = int16 | int8
777-
_int32_max: TypeAlias = int32 | _int16_max
778716
_float32_min: TypeAlias = float32 | float64 | longdouble
779717
_float32_max: TypeAlias = float32 | float16
780718
_float64_max: TypeAlias = float64 | _float32_max
@@ -784,12 +722,7 @@ _integer32_min: TypeAlias = _nt.integer32 | _nt.integer64
784722
_inexact64_min: TypeAlias = _nt.inexact64 | _nt.inexact64l
785723
_inexact64_max: TypeAlias = _float64_max | _complex128_max
786724

787-
_ArrayUInt_co: TypeAlias = _nt.Array[_nt.co_uint64]
788-
_ArrayInt_co: TypeAlias = _nt.Array[_nt.co_int64]
789725
_ArrayInteger_co: TypeAlias = _nt.Array[_nt.co_integer]
790-
_ArrayFloat64_co: TypeAlias = _nt.Array[_nt.co_float64]
791-
_ArrayFloat_co: TypeAlias = _nt.Array[_nt.co_float]
792-
_ArrayComplex128_co: TypeAlias = _nt.Array[_nt.co_complex128]
793726
_ArrayComplex_co: TypeAlias = _nt.Array[_nt.co_complex]
794727
_ArrayTD64_co: TypeAlias = _nt.Array[_nt.co_timedelta]
795728

@@ -798,21 +731,6 @@ _ToIndices: TypeAlias = _ToIndex | tuple[_ToIndex, ...]
798731

799732
_Axis0D: TypeAlias = L[0, -1] | tuple[()]
800733

801-
_UnsignedIntegerCType: TypeAlias = type[
802-
ct.c_uint8 | ct.c_uint16 | ct.c_uint32 | ct.c_uint64
803-
| ct.c_ushort | ct.c_uint | ct.c_ulong | ct.c_ulonglong
804-
| ct.c_size_t | ct.c_void_p
805-
] # fmt: skip
806-
_SignedIntegerCType: TypeAlias = type[
807-
ct.c_int8 | ct.c_int16 | ct.c_int32 | ct.c_int64
808-
| ct.c_short | ct.c_int | ct.c_long | ct.c_longlong
809-
| ct.c_ssize_t
810-
] # fmt: skip
811-
_FloatingCType: TypeAlias = type[ct.c_float | ct.c_double | ct.c_longdouble]
812-
_IntegerCType: TypeAlias = _UnsignedIntegerCType | _SignedIntegerCType
813-
_NumberCType: TypeAlias = _IntegerCType
814-
_GenericCType: TypeAlias = _NumberCType | type[ct.c_bool | ct.c_char | ct.py_object[Any]]
815-
816734
_PyBoolND: TypeAlias = _nt.SequenceND[py_bool]
817735
_PyCoIntND: TypeAlias = _nt.SequenceND[int]
818736
_PyCoFloatND: TypeAlias = _nt.SequenceND[float]
@@ -821,11 +739,6 @@ _PyIntND: TypeAlias = _nt.SequenceND[_nt.JustInt]
821739
_PyFloatND: TypeAlias = _nt.SequenceND[_nt.JustFloat]
822740
_PyComplexND: TypeAlias = _nt.SequenceND[_nt.JustComplex]
823741

824-
# some commonly used builtin types that are known to result in a
825-
# `dtype[object_]`, when their *type* is passed to the `dtype` constructor
826-
# NOTE: `builtins.object` should not be included here
827-
_BuiltinObjectLike: TypeAlias = Decimal | Fraction
828-
829742
# can be anything, is case-insensitive, and only the first character matters
830743
_ByteOrder: TypeAlias = L[
831744
"S", # swap the current order (default)
@@ -898,7 +811,7 @@ _DTypeBuiltinKind: TypeAlias = L[0, 1, 2]
898811
_ArrayAPIVersion: TypeAlias = L["2021.12", "2022.12", "2023.12"]
899812
_Device: TypeAlias = L["cpu"]
900813

901-
_OrderCF: TypeAlias = L["C", "F"] | None
814+
_OrderCF: TypeAlias = L["C", "F"] | None # noqa: PYI047
902815
_OrderACF: TypeAlias = L["A", "C", "F"] | None
903816
_OrderKACF: TypeAlias = L["K", "A", "C", "F"] | None
904817

@@ -941,7 +854,6 @@ _IntTD64Unit: TypeAlias = L[_MonthUnit, _IntTimeUnit]
941854
_TD64Unit: TypeAlias = L[_DateUnit, _TimeUnit]
942855
_TimeUnitSpec: TypeAlias = _TD64UnitT | tuple[_TD64UnitT, CanIndex]
943856

944-
_BinOperandComplex128_co: TypeAlias = complex | float64 | _integer32_min
945857
_ToReal: TypeAlias = float | CanComplex | CanFloat | CanIndex
946858
_ToImag: TypeAlias = float | CanFloat | CanIndex
947859

‎src/numpy-stubs/_core/_dtype.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import numpy as np
77

88
_T = TypeVar("_T")
99

10-
_Kind: TypeAlias = L["u", "i", "c", "f", "b", "V", "O", "M", "m", "S", "U"]
1110
_Name: TypeAlias = L[
1211
"uint", "int", "complex", "float", "bool", "void", "object", "datetime", "timedelta", "bytes", "str"
1312
]

‎src/numpy-stubs/_core/overrides.pyi

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections.abc import Callable, Iterable
2-
from typing import Any, Final, NamedTuple, TypeAlias
2+
from typing import Any, Final, NamedTuple
33
from typing_extensions import ParamSpec, TypeVar
44

55
from numpy._typing import _SupportsArrayFunc
@@ -8,8 +8,6 @@ _T = TypeVar("_T")
88
_Tss = ParamSpec("_Tss")
99
_FuncT = TypeVar("_FuncT", bound=Callable[..., object])
1010

11-
_AnyFunc: TypeAlias = Callable[..., Any]
12-
1311
###
1412

1513
ARRAY_FUNCTIONS: set[Callable[..., Any]] = ...
@@ -21,7 +19,7 @@ class ArgSpec(NamedTuple):
2119
keywords: str | None
2220
defaults: tuple[Any, ...]
2321

24-
def get_array_function_like_doc(public_api: Callable[..., Any], docstring_template: str = "") -> str: ...
22+
def get_array_function_like_doc(public_api: Callable[..., object], docstring_template: str = "") -> str: ...
2523
def finalize_array_function_like(public_api: _FuncT) -> _FuncT: ...
2624

2725
#

‎src/numpy-stubs/_typing/__init__.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ from ._array_like import (
1919
_ArrayLikeTD64_co as _ArrayLikeTD64_co,
2020
_ArrayLikeUInt_co as _ArrayLikeUInt_co,
2121
_ArrayLikeVoid_co as _ArrayLikeVoid_co,
22-
_FiniteNestedSequence as _FiniteNestedSequence,
2322
_SupportsArray as _SupportsArray,
2423
_SupportsArrayFunc as _SupportsArrayFunc,
2524
)

‎src/numpy-stubs/_typing/_array_like.pyi

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from collections.abc import Callable, Collection, Sequence
1+
from collections.abc import Callable, Collection
22
from typing import Any, Protocol, TypeAlias, runtime_checkable
33
from typing_extensions import Buffer, TypeVar
44

@@ -35,14 +35,6 @@ class _SupportsArrayFunc(Protocol): # noqa: PYI046
3535
kwargs: dict[str, Any],
3636
) -> object: ...
3737

38-
_FiniteNestedSequence: TypeAlias = (
39-
_T
40-
| Sequence[_T]
41-
| Sequence[Sequence[_T]]
42-
| Sequence[Sequence[Sequence[_T]]]
43-
| Sequence[Sequence[Sequence[Sequence[_T]]]]
44-
)
45-
4638
# A subset of `npt.ArrayLike` that can be parametrized w.r.t. `np.generic`
4739
_ArrayLike: TypeAlias = _SupportsArray[np.dtype[_ScalarT]] | _NestedSequence[_SupportsArray[np.dtype[_ScalarT]]]
4840

@@ -55,6 +47,11 @@ _DualArrayLike: TypeAlias = (
5547

5648
ArrayLike: TypeAlias = _DualArrayLike[np.dtype, complex | str | bytes] | Buffer
5749

50+
# TODO(jorenham): get rid of this in favor of the ones in `_numtype`
51+
# https://github.com/numpy/numtype/issues/568
52+
53+
# ruff: noqa: PYI047
54+
5855
# `ArrayLike<X>_co`: array-like objects that can be coerced into `X`
5956
# given the casting rules `same_kind`
6057
_ArrayLikeBool_co: TypeAlias = _DualArrayLike[np.dtype[np.bool], bool]

‎src/numpy-stubs/_typing/_char_codes.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
from typing import Literal, TypeAlias
22

3+
# TODO(jorenham): move these to `_numtype` instead
4+
# https://github.com/numpy/numtype/issues/567
5+
6+
# ruff: noqa: PYI047
7+
38
_BoolCodes: TypeAlias = Literal["bool", "bool_", "b1", "?", "|?", "=?", "<?", ">?", "\x00"]
49

510
_Int8Codes: TypeAlias = Literal["int8", "byte", "i1", "b", "|i1", "|b", "=i1", "=b", "<i1", "<b", ">i1", ">b", "\x01"]

‎src/numpy-stubs/_typing/_dtype_like.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ _DTypeLike: TypeAlias = type[_ScalarT] | np.dtype[_ScalarT] | _SupportsDType[np.
4848
# Would create a dtype[np.void]
4949
_VoidDTypeLike: TypeAlias = tuple[Any, Any] | list[Any] | _DTypeDict
5050

51+
# TODO(jorenahm): remove these `_DTypeLike*` aliases in favor of `_numtype.ToDType*`:
52+
# https://github.com/numpy/numtype/issues/566
53+
# ruff: noqa: PYI047
54+
5155
# Aliases for commonly used dtype-like objects.
5256
# Note that the precision of `np.number` subclasses is ignored herein.
5357
_DTypeLikeBool: TypeAlias = type[bool] | _DTypeLike[np.bool] | _BoolCodes

‎src/numpy-stubs/_typing/_scalars.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
# TODO(jorenham): get rid of these in favor of `_?numtype`
2+
13
from typing import Any, TypeAlias
24

35
import numpy as np
46

7+
# ruff: noqa: PYI047
8+
59
# NOTE: `_StrLike_co` and `_BytesLike_co` are pointless, as `np.str_` and
610
# `np.bytes_` are already subclasses of their builtin counterpart
711
_CharLike_co: TypeAlias = str | bytes
@@ -14,7 +18,7 @@ _IntLike_co: TypeAlias = int | np.integer | np.bool
1418
_FloatLike_co: TypeAlias = float | np.floating | np.integer | np.bool
1519
_ComplexLike_co: TypeAlias = complex | np.number | np.bool
1620
_NumberLike_co = _ComplexLike_co
17-
_TD64Like_co: TypeAlias = int | np.timedelta64 | np.integer | np.bool
21+
_TD64Like_co: TypeAlias = _IntLike_co | np.timedelta64
1822
_ScalarLike_co: TypeAlias = complex | bytes | str | np.generic
1923

2024
# `_VoidLike_co` is technically not a scalar, but it's close enough
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from collections.abc import Sequence
22
from typing import SupportsIndex, TypeAlias
33

4+
# TODO(jorenham): https://github.com/numpy/numtype/issues/565
5+
46
# Anything that can be coerced to a shape tuple
5-
_ShapeLike: TypeAlias = SupportsIndex | Sequence[SupportsIndex]
7+
_ShapeLike: TypeAlias = SupportsIndex | Sequence[SupportsIndex] # noqa: PYI047

‎src/numpy-stubs/linalg/_linalg.pyi

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ __all__ = [
4646

4747
###
4848

49-
_SafeFloating: TypeAlias = np.float32 | np.float64
50-
_SafeInexact: TypeAlias = _SafeFloating | np.complex64 | np.complex128
51-
5249
_T = TypeVar("_T")
5350
_ArrayT = TypeVar("_ArrayT", bound=_nt.Array[Any])
5451
_Shape2NDT = TypeVar("_Shape2NDT", bound=_nt.Shape2N)
@@ -97,7 +94,6 @@ _ToInt: TypeAlias = SupportsInt | CanIndex
9794
_Ax2: TypeAlias = _ToInt | _2Tuple[_ToInt]
9895
_Axes: TypeAlias = Iterable[int]
9996

100-
_ArrayOrScalar: TypeAlias = _ScalarT | _nt.Array[_ScalarT]
10197
_Ord: TypeAlias = L[1, -1, 2, -2, "fro", "nuc"] | float
10298
_UPLO: TypeAlias = L["L", "U", "l", "u"]
10399

0 commit comments

Comments
 (0)