Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/numpy-stubs/@test/runtime/legacy/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

class Object:
def __array__(
self, dtype: npt.DTypeLike = None, *, copy: bool | None = None
self, dtype: npt.DTypeLike | None = None, *, copy: bool | None = None
) -> npt.NDArray[np.object_]:
ret = np.empty((), dtype=np.object_)
ret[()] = self
Expand Down
32 changes: 16 additions & 16 deletions src/numpy-stubs/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta):
) -> Self: ...
@overload
def __new__(
cls, dtype: DTypeLike, align: py_bool = False, copy: py_bool = False, *, metadata: _MetaData = ...
cls, dtype: DTypeLike | None, align: py_bool = False, copy: py_bool = False, *, metadata: _MetaData = ...
) -> dtype: ...

#
Expand All @@ -1235,10 +1235,10 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta):
def __ne__(self, other: object, /) -> py_bool: ...

#
def __gt__(self, other: DTypeLike, /) -> py_bool: ...
def __ge__(self, other: DTypeLike, /) -> py_bool: ...
def __lt__(self, other: DTypeLike, /) -> py_bool: ...
def __le__(self, other: DTypeLike, /) -> py_bool: ...
def __gt__(self, other: DTypeLike | None, /) -> py_bool: ...
def __ge__(self, other: DTypeLike | None, /) -> py_bool: ...
def __lt__(self, other: DTypeLike | None, /) -> py_bool: ...
def __le__(self, other: DTypeLike | None, /) -> py_bool: ...

# NOTE: In the future 1-based multiplications will also yield `flexible` dtypes
@overload
Expand Down Expand Up @@ -1752,7 +1752,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
def __new__(
cls,
shape: _ShapeLike,
dtype: DTypeLike = float, # noqa: PYI011
dtype: DTypeLike | None = float, # noqa: PYI011
buffer: Buffer | None = None,
offset: CanIndex = 0,
strides: _ShapeLike | None = None,
Expand Down Expand Up @@ -3125,7 +3125,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
def astype(
self,
/,
dtype: DTypeLike,
dtype: DTypeLike | None,
order: _OrderKACF = "K",
casting: _CastingKind = "unsafe",
subok: py_bool = True,
Expand Down Expand Up @@ -3186,18 +3186,18 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
@overload # (_: T)
def view(self, /, dtype: type[_ArrayT]) -> _ArrayT: ...
@overload # (dtype: ?)
def view(self, /, dtype: DTypeLike) -> ndarray[_ShapeT_co]: ...
def view(self, /, dtype: DTypeLike | None) -> ndarray[_ShapeT_co]: ...
@overload # (dtype: ?, type: type[T])
def view(self, /, dtype: DTypeLike, type: type[_ArrayT]) -> _ArrayT: ...
def view(self, /, dtype: DTypeLike | None, type: type[_ArrayT]) -> _ArrayT: ...

#
@overload
def getfield(self, /, dtype: _DTypeLike[_ScalarT], offset: CanIndex = 0) -> _nt.Array[_ScalarT]: ...
@overload
def getfield(self, /, dtype: DTypeLike, offset: CanIndex = 0) -> _nt.Array: ...
def getfield(self, /, dtype: DTypeLike | None, offset: CanIndex = 0) -> _nt.Array: ...

#
def setfield(self, val: ArrayLike, /, dtype: DTypeLike, offset: CanIndex = 0) -> None: ...
def setfield(self, val: ArrayLike, /, dtype: DTypeLike | None, offset: CanIndex = 0) -> None: ...

# keep `dtype` at the bottom to avoid shadowing
@property
Expand Down Expand Up @@ -3333,7 +3333,7 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]):
def astype(
self,
/,
dtype: DTypeLike,
dtype: DTypeLike | None,
order: _OrderKACF = "K",
casting: _CastingKind = "unsafe",
subok: py_bool = True,
Expand All @@ -3352,15 +3352,15 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]):
@overload
def view(self, /, dtype: _DTypeLike[_ScalarT], type: type[_nt.Array]) -> _ScalarT: ...
@overload
def view(self, /, dtype: DTypeLike) -> Incomplete: ...
def view(self, /, dtype: DTypeLike | None) -> Incomplete: ...
@overload
def view(self, /, dtype: DTypeLike, type: type[_nt.Array]) -> Incomplete: ...
def view(self, /, dtype: DTypeLike | None, type: type[_nt.Array]) -> Incomplete: ...

#
@overload
def getfield(self, /, dtype: _DTypeLike[_ScalarT], offset: CanIndex = 0) -> _ScalarT: ...
@overload
def getfield(self, /, dtype: DTypeLike, offset: CanIndex = 0) -> Incomplete: ...
def getfield(self, /, dtype: DTypeLike | None, offset: CanIndex = 0) -> Incomplete: ...

#
@overload
Expand Down Expand Up @@ -5039,7 +5039,7 @@ class void(flexible[bytes | tuple[Any, ...]]): # type: ignore[misc] # pyright:
def __getitem__(self, key: list[str], /) -> void: ...
def __setitem__(self, key: str | list[str] | CanIndex, value: ArrayLike, /) -> None: ...
@override
def setfield(self, val: ArrayLike, dtype: DTypeLike, offset: int = 0) -> None: ...
def setfield(self, val: ArrayLike, dtype: DTypeLike | None, offset: int = 0) -> None: ...

#
@property
Expand Down
46 changes: 29 additions & 17 deletions src/numpy-stubs/_core/_multiarray_umath.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def empty(
@overload # 1d shape, unknown dtype
def empty(
shape: _ShapeLike1D,
dtype: npt.DTypeLike = None,
dtype: npt.DTypeLike | None = None,
order: _OrderCF = "C",
*,
device: _Device | None = None,
Expand Down Expand Up @@ -554,7 +554,7 @@ def empty(
@overload # known shape, unknown scalar-type
def empty(
shape: _AnyShapeT,
dtype: npt.DTypeLike = None,
dtype: npt.DTypeLike | None = None,
order: _OrderCF = "C",
*,
device: _Device | None = None,
Expand Down Expand Up @@ -590,7 +590,7 @@ def empty(
@overload # unknown shape, unknown dtype
def empty(
shape: _ShapeLike,
dtype: npt.DTypeLike = ...,
dtype: npt.DTypeLike | None = None,
order: _OrderCF = "C",
*,
device: _Device | None = None,
Expand All @@ -601,7 +601,7 @@ def empty(
@overload # 1d shape, default dtype (float64)
def zeros(
shape: _ShapeLike1D,
dtype: _nt.ToDTypeFloat64 = ...,
dtype: _nt.ToDTypeFloat64 | None = None,
order: _OrderCF = "C",
*,
device: _Device | None = None,
Expand All @@ -628,7 +628,7 @@ def zeros(
@overload # 1d shape, unknown dtype
def zeros(
shape: _ShapeLike1D,
dtype: npt.DTypeLike = ...,
dtype: npt.DTypeLike | None = None,
order: _OrderCF = "C",
*,
device: _Device | None = None,
Expand Down Expand Up @@ -664,7 +664,7 @@ def zeros(
@overload # known shape, unknown scalar-type
def zeros(
shape: _AnyShapeT,
dtype: npt.DTypeLike = ...,
dtype: npt.DTypeLike | None = None,
order: _OrderCF = "C",
*,
device: _Device | None = None,
Expand Down Expand Up @@ -700,7 +700,7 @@ def zeros(
@overload # unknown shape, unknown dtype
def zeros(
shape: _ShapeLike,
dtype: npt.DTypeLike = ...,
dtype: npt.DTypeLike | None = None,
order: _OrderCF = "C",
*,
device: _Device | None = None,
Expand Down Expand Up @@ -1350,7 +1350,7 @@ def asfortranarray(
@overload
def fromstring(
string: bytes | str,
dtype: type[_nt.JustFloat] | None = ...,
dtype: type[_nt.JustFloat] | None = float, # noqa: PYI011
count: CanIndex = -1,
*,
sep: str,
Expand All @@ -1367,11 +1367,21 @@ def fromstring(
) -> _nt.Array[_ScalarT]: ...
@overload
def fromstring(
string: bytes | str, dtype: npt.DTypeLike = ..., count: CanIndex = -1, *, sep: str, like: _nt.Array[_ScalarT]
string: bytes | str,
dtype: npt.DTypeLike | None = float, # noqa: PYI011
count: CanIndex = -1,
*,
sep: str,
like: _nt.Array[_ScalarT],
) -> _nt.Array[_ScalarT]: ...
@overload
def fromstring(
string: bytes | str, dtype: npt.DTypeLike, count: CanIndex = -1, *, sep: str, like: _CanArrayFunc | None = None
string: bytes | str,
dtype: npt.DTypeLike | None,
count: CanIndex = -1,
*,
sep: str,
like: _CanArrayFunc | None = None,
) -> _nt.Array[Incomplete]: ...

#
Expand All @@ -1392,7 +1402,7 @@ def fromfile(
@overload
def fromfile(
file: _ToFile,
dtype: npt.DTypeLike,
dtype: npt.DTypeLike | None,
count: CanIndex = -1,
sep: str = "",
offset: CanIndex = 0,
Expand All @@ -1407,7 +1417,7 @@ def fromiter(
) -> _nt.Array[_ScalarT]: ...
@overload
def fromiter(
iter: Iterable[object], dtype: npt.DTypeLike, count: CanIndex = -1, *, like: _CanArrayFunc | None = None
iter: Iterable[object], dtype: npt.DTypeLike | None, count: CanIndex = -1, *, like: _CanArrayFunc | None = None
) -> _nt.Array[Incomplete]: ...

#
Expand All @@ -1427,7 +1437,7 @@ def frombuffer(
@overload
def frombuffer(
buffer: Buffer,
dtype: npt.DTypeLike,
dtype: npt.DTypeLike | None,
count: CanIndex = -1,
offset: CanIndex = 0,
*,
Expand Down Expand Up @@ -1650,10 +1660,12 @@ def shares_memory(a: object, b: object, /, max_work: L[0, -1] = -1) -> bool: ...
def may_share_memory(a: object, b: object, /, max_work: L[0, -1] = 0) -> bool: ...

#
def can_cast(from_: npt.ArrayLike | npt.DTypeLike, to: npt.DTypeLike, casting: _CastingKind = "safe") -> bool: ...
def can_cast(
from_: npt.ArrayLike | npt.DTypeLike | None, to: npt.DTypeLike | None, casting: _CastingKind = "safe"
) -> bool: ...
def min_scalar_type(a: npt.ArrayLike, /) -> np.dtype[Incomplete]: ...
def result_type(*arrays_and_dtypes: npt.ArrayLike | npt.DTypeLike) -> np.dtype[Incomplete]: ...
def promote_types(type1: npt.DTypeLike, type2: npt.DTypeLike, /) -> np.dtype[Incomplete]: ...
def result_type(*arrays_and_dtypes: npt.ArrayLike | npt.DTypeLike | None) -> np.dtype[Incomplete]: ...
def promote_types(type1: npt.DTypeLike | None, type2: npt.DTypeLike | None, /) -> np.dtype[Incomplete]: ...

#
@overload
Expand Down Expand Up @@ -2011,4 +2023,4 @@ def _make_extobj() -> CapsuleType: ...
def _monotonicity(x: _nt.CoFloating_nd) -> L[0, 1]: ...
def _place(input: npt.ArrayLike, mask: _nt.ToBool_nd, vals: npt.ArrayLike) -> None: ...
def _reconstruct(subtype: type[_nt.Array], shape: _AnyShapeT, dtype: _DTypeT) -> np.ndarray[_AnyShapeT, _DTypeT]: ...
def _vec_string(a: _ArrayLikeAnyString_co, dtype: npt.DTypeLike, attr: str, /) -> _nt.Array[Incomplete]: ...
def _vec_string(a: _ArrayLikeAnyString_co, dtype: npt.DTypeLike | None, attr: str, /) -> _nt.Array[Incomplete]: ...
6 changes: 3 additions & 3 deletions src/numpy-stubs/_core/function_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def linspace(
num: SupportsIndex = 50,
endpoint: bool = True,
retstep: L[False] = False,
dtype: DTypeLike = ...,
dtype: DTypeLike | None = None,
axis: SupportsIndex = 0,
*,
device: _Device | None = None,
Expand Down Expand Up @@ -120,7 +120,7 @@ def linspace(
endpoint: bool = True,
*,
retstep: L[True],
dtype: DTypeLike = ...,
dtype: DTypeLike | None = None,
axis: SupportsIndex = 0,
device: _Device | None = None,
) -> tuple[_nt.Array[Incomplete], Incomplete]: ...
Expand Down Expand Up @@ -174,7 +174,7 @@ def logspace(
num: SupportsIndex = 50,
endpoint: bool = True,
base: _ArrayLikeNumber_co = 10.0,
dtype: DTypeLike = ...,
dtype: DTypeLike | None = None,
axis: SupportsIndex = 0,
) -> _nt.Array[Incomplete]: ...

Expand Down
2 changes: 1 addition & 1 deletion src/numpy-stubs/_core/memmap.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class memmap(np.ndarray[_ShapeT_co, _DType_co], Generic[_ShapeT_co, _DType_co]):
def __new__(
subtype,
filename: _ToFileName,
dtype: npt.DTypeLike,
dtype: npt.DTypeLike | None,
mode: _ToMode = "r+",
offset: int = 0,
shape: int | tuple[int, ...] | None = None,
Expand Down
Loading