diff options
| author | Bas van Beek <43369155+BvB93@users.noreply.github.com> | 2021-06-18 13:18:29 +0200 |
|---|---|---|
| committer | Bas van Beek <43369155+BvB93@users.noreply.github.com> | 2021-06-18 13:34:59 +0200 |
| commit | 9ce2c360384ed15f5a0618b5d64d0e09615bf15f (patch) | |
| tree | 202a5d9976370fd311d00bd1f7b2871c8af991aa | |
| parent | 14b5ed70b02d155ddb8988db3413a29f9a119285 (diff) | |
| download | numpy-9ce2c360384ed15f5a0618b5d64d0e09615bf15f.tar.gz | |
MAINT: Fixed the signature of `dtype.__mul__`
* Multiplication by 0 does not return `None`
* Multiplication of a flexible dtype returns a flexible dtype; not just void
* In principle any object implementing the `__index__` protocol is a valid multiplication value; not just integers.
| -rw-r--r-- | numpy/__init__.pyi | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi index 33b26952f..892276053 100644 --- a/numpy/__init__.pyi +++ b/numpy/__init__.pyi @@ -1053,17 +1053,21 @@ class dtype(Generic[_DTypeScalar_co]): @overload def __getitem__(self: dtype[void], key: str | int) -> dtype[Any]: ... - # NOTE: In the future 1-based multiplications will also yield `void` dtypes - @overload - def __mul__(self, value: L[0]) -> None: ... # type: ignore[misc] + # NOTE: In the future 1-based multiplications will also yield `flexible` dtypes @overload def __mul__(self: _DType, value: L[1]) -> _DType: ... @overload - def __mul__(self, value: int) -> dtype[void]: ... + def __mul__(self: _FlexDType, value: SupportsIndex) -> _FlexDType: ... + @overload + def __mul__(self, value: SupportsIndex) -> dtype[void]: ... # NOTE: `__rmul__` seems to be broken when used in combination with - # literals as of mypy 0.800. Set the return-type to `Any` for now. - def __rmul__(self, value: int) -> Any: ... + # literals as of mypy 0.902. Set the return-type to `dtype[Any]` for + # now for non-flexible dtypes. + @overload + def __rmul__(self: _FlexDType, value: SupportsIndex) -> _FlexDType: ... + @overload + def __rmul__(self, value: SupportsIndex) -> dtype[Any]: ... def __gt__(self, other: DTypeLike) -> bool: ... def __ge__(self, other: DTypeLike) -> bool: ... @@ -1592,6 +1596,7 @@ class _ArrayOrScalarCommon: _DType = TypeVar("_DType", bound=dtype[Any]) _DType_co = TypeVar("_DType_co", covariant=True, bound=dtype[Any]) +_FlexDType = TypeVar("_FlexDType", bound=dtype[flexible]) # TODO: Set the `bound` to something more suitable once we # have proper shape support |
