TYP: fix stubtest errors in numpy.lib._function_base_impl#28527
TYP: fix stubtest errors in numpy.lib._function_base_impl#28527charris merged 1 commit intonumpy:mainfrom
numpy.lib._function_base_impl#28527Conversation
Ported from numpy/numtype#233 --- This fixes the signatures of the following public `numpy` members: - `average` - `ma.average` - `median` - `corrcoef`
|
I note that there are differences between Which certainly looks suspicious. |
This comment was marked as outdated.
This comment was marked as outdated.
This can be traced back to fca2d02#diff-66e41e3d5dbb0f4563cbcc551193d550eb8cfb0f502b806ab5079792d6e9bf3b |
|
Ah, most of the differences were ruff style cleanups, that is why it wasn't backported. Seems there were some fixes as well. |
Maybe this |
|
The easy thing to do is just co the file from main. I don't mind the style cleanups, they just weren't worth the effort to backport. |
That will cause problems, because several deprecated methods that will be removed in 2.3 should still remain in 2.2. To illustrate, this is the current diff: diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi
index 539c5fa53c..812ea117b0 100644
--- a/numpy/__init__.pyi
+++ b/numpy/__init__.pyi
@@ -227,7 +227,7 @@
# library include `typing_extensions` stubs:
# https://github.com/python/typeshed/blob/main/stdlib/typing_extensions.pyi
from _typeshed import StrOrBytesPath, SupportsFlush, SupportsLenAndGetItem, SupportsWrite
-from typing_extensions import CapsuleType, LiteralString, Never, Protocol, Self, TypeVar, Unpack, deprecated, overload
+from typing_extensions import CapsuleType, LiteralString, Never, Protocol, Self, TypeVar, Unpack, overload
from numpy import (
char,
@@ -880,7 +880,7 @@
] # fmt: skip
_FloatingCType: TypeAlias = type[ct.c_float | ct.c_double | ct.c_longdouble]
_IntegerCType: TypeAlias = _UnsignedIntegerCType | _SignedIntegerCType
-_NumberCType: TypeAlias = _IntegerCType | _IntegerCType
+_NumberCType: TypeAlias = _IntegerCType
_GenericCType: TypeAlias = _NumberCType | type[ct.c_bool | ct.c_char | ct.py_object[Any]]
# some commonly used builtin types that are known to result in a
@@ -898,11 +898,11 @@
_ByteOrderChar: TypeAlias = L["<", ">", "=", "|"]
# can be anything, is case-insensitive, and only the first character matters
_ByteOrder: TypeAlias = L[
- "S", # swap the current order (default)
- "<", "L", "little", # little-endian
- ">", "B", "big", # big endian
- "=", "N", "native", # native order
- "|", "I", # ignore
+ "S", # swap the current order (default)
+ "<", "L", "little", # little-endian
+ ">", "B", "big", # big endian
+ "=", "N", "native", # native order
+ "|", "I", # ignore
] # fmt: skip
_DTypeKind: TypeAlias = L[
"b", # boolean
@@ -982,9 +982,9 @@
_CastingKind: TypeAlias = L["no", "equiv", "safe", "same_kind", "unsafe"]
-_OrderKACF: TypeAlias = L[None, "K", "A", "C", "F"]
-_OrderACF: TypeAlias = L[None, "A", "C", "F"]
-_OrderCF: TypeAlias = L[None, "C", "F"]
+_OrderKACF: TypeAlias = L["K", "A", "C", "F"] | None
+_OrderACF: TypeAlias = L["A", "C", "F"] | None
+_OrderCF: TypeAlias = L["C", "F"] | None
_ModeKind: TypeAlias = L["raise", "wrap", "clip"]
_PartitionKind: TypeAlias = L["introselect"]
@@ -999,7 +999,7 @@
_SortSide: TypeAlias = L["left", "right"]
_ConvertibleToInt: TypeAlias = SupportsInt | SupportsIndex | _CharLike_co
-_ConvertibleToFloat: TypeAlias = SupportsFloat | SupportsIndex | _CharLike_co
+_ConvertibleToFloat: TypeAlias = SupportsFloat | SupportsIndex | _CharLike_co
if sys.version_info >= (3, 11):
_ConvertibleToComplex: TypeAlias = SupportsComplex | SupportsFloat | SupportsIndex | _CharLike_co
else:
@@ -1049,7 +1049,7 @@
_DT64Date: TypeAlias = _HasDateAttributes | L["TODAY", "today", b"TODAY", b"today"]
_DT64Now: TypeAlias = L["NOW", "now", b"NOW", b"now"]
-_NaTValue: TypeAlias = L["NAT","NaT", "nat",b"NAT", b"NaT", b"nat"]
+_NaTValue: TypeAlias = L["NAT", "NaT", "nat", b"NAT", b"NaT", b"nat"]
_MonthUnit: TypeAlias = L["Y", "M", b"Y", b"M"]
_DayUnit: TypeAlias = L["W", "D", b"W", b"D"]
@@ -1082,8 +1082,7 @@ def tell(self) -> SupportsIndex: ...
def seek(self, offset: int, whence: int, /) -> object: ...
@type_check_only
-class _SupportsFileMethodsRW(SupportsWrite[bytes], _SupportsFileMethods, Protocol):
- pass
+class _SupportsFileMethodsRW(SupportsWrite[bytes], _SupportsFileMethods, Protocol): ...
@type_check_only
class _SupportsItem(Protocol[_T_co]):
@@ -1150,7 +1149,6 @@ def month(self) -> int: ...
@property
def year(self) -> int: ...
-
### Mixins (for internal use only)
@type_check_only
@@ -1635,7 +1633,6 @@ def str(self) -> LiteralString: ...
@property
def type(self) -> type[_SCT_co]: ...
-
@final
class flatiter(Generic[_ArrayT_co]):
__hash__: ClassVar[None]
@@ -1713,8 +1710,6 @@ def copy(self, order: _OrderKACF = ...) -> Self: ...
def dump(self, file: StrOrBytesPath | SupportsWrite[bytes]) -> None: ...
def dumps(self) -> bytes: ...
def tobytes(self, order: _OrderKACF = ...) -> bytes: ...
- # NOTE: `tostring()` is deprecated and therefore excluded
- # def tostring(self, order=...): ...
def tofile(self, fid: StrOrBytesPath | _SupportsFileMethods, sep: str = ..., format: str = ...) -> None: ...
# generics and 0d arrays return builtin scalars
def tolist(self) -> Any: ...
@@ -3903,8 +3898,6 @@ def __int__(self: np.bool[L[False]], /) -> L[0]: ...
def __int__(self: np.bool[L[True]], /) -> L[1]: ...
@overload
def __int__(self, /) -> L[0, 1]: ...
- @deprecated("In future, it will be an error for 'np.bool' scalars to be interpreted as an index")
- def __index__(self, /) -> L[0, 1]: ...
def __abs__(self) -> Self: ...
@overload
@@ -4279,7 +4272,6 @@ def __rmod__(self, other: _Float64_co, /) -> float64: ... # type: ignore[overri
def __divmod__(self, other: _Float64_co, /) -> _2Tuple[float64]: ... # type: ignore[override]
def __rdivmod__(self, other: _Float64_co, /) -> _2Tuple[float64]: ... # type: ignore[override]
-
half: TypeAlias = floating[_NBitHalf]
single: TypeAlias = floating[_NBitSingle]
double: TypeAlias = floating[_NBitDouble]
@@ -4308,11 +4300,6 @@ def imag(self) -> floating[_NBit2]: ... # type: ignore[override]
# NOTE: `__complex__` is technically defined in the concrete subtypes
def __complex__(self, /) -> complex: ...
def __abs__(self, /) -> floating[_NBit1 | _NBit2]: ... # type: ignore[override]
- @deprecated(
- "The Python built-in `round` is deprecated for complex scalars, and will raise a `TypeError` in a future release. "
- "Use `np.round` or `scalar.round` instead."
- )
- def __round__(self, /, ndigits: SupportsIndex | None = None) -> Self: ...
@overload
def __add__(self, other: _Complex64_co, /) -> complexfloating[_NBit1, _NBit2]: ...
@@ -5036,7 +5023,6 @@ def __new__(
cls, dtype: str
) -> finfo[floating[Any]]: ...
-
class iinfo(Generic[_IntegerT_co]):
dtype: Final[dtype[_IntegerT_co]]
kind: Final[LiteralString]
@@ -5269,7 +5255,6 @@ def integ(
k: None | _ArrayLikeComplex_co | _ArrayLikeObject_co = ...,
) -> poly1d: ...
-
class matrix(ndarray[_2DShapeT_co, _DType_co]):
__array_priority__: ClassVar[float]
def __new__(
@@ -5406,7 +5391,7 @@ def flatten(self, /, order: _OrderKACF = "C") -> matrix[tuple[L[1], int], _DType
@property
def T(self) -> matrix[_2D, _DType_co]: ...
@property
- def I(self) -> matrix[_2D, Any]: ...
+ def I(self) -> matrix[_2D, Any]: ... # noqa: E743
@property
def A(self) -> ndarray[_2DShapeT_co, _DType_co]: ...
@property
@@ -5419,7 +5404,6 @@ def getA(self) -> ndarray[_2DShapeT_co, _DType_co]: ...
def getA1(self) -> ndarray[_Shape, _DType_co]: ...
def getH(self) -> matrix[_2D, _DType_co]: ...
-
def from_dlpack(
x: _SupportsDLPack[None],
/, |
Ported from numpy/numtype#233
This fixes the signatures of the following public
numpymembers:averagema.averagemedianpercentilecorrcoef