8000 MAINT: Misc cleaning of `numpy.typing` by BvB93 · Pull Request #19118 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: Misc cleaning of numpy.typing #19118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
STY: Use the PEP 604 pipe operator over Optional and Union
PEP 604 -- Allow writing union types as X | Y
  • Loading branch information
Bas van Beek committed May 27, 2021
commit 757eb4abd1b6823d4d7933c9ad0c75160750833b
4 changes: 2 additions & 2 deletions numpy/typing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@ class NBitBase:
.. code-block:: python

>>> from __future__ import annotations
>>> from typing import TypeVar, Union, TYPE_CHECKING
>>> from typing import TypeVar, TYPE_CHECKING
>>> import numpy as np
>>> import numpy.typing as npt

>>> T1 = TypeVar("T1", bound=npt.NBitBase)
>>> T2 = TypeVar("T2", bound=npt.NBitBase)

>>> def add(a: np.floating[T1], b: np.integer[T2]) -> np.floating[Union[T1, T2]]:
>>> def add(a: np.floating[T1], b: np.integer[T2]) -> np.floating[T1 | T2]:
... return a + b

>>> a = np.float16()
Expand Down
92 changes: 46 additions & 46 deletions numpy/typing/_callable.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def __call__(self, __other: _NumberType) -> _NumberType: ...

class _BoolTrueDiv(Protocol):
@overload
def __call__(self, __other: Union[float, _IntLike_co]) -> float64: ...
def __call__(self, __other: float | _IntLike_co) -> float64: ...
@overload
def __call__(self, __other: complex) -> complex128: ...
@overload
Expand All @@ -126,7 +126,7 @@ def __call__(self, __other: _BoolLike_co) -> _2Tuple[int8]: ...
@overload # platform dependent
def __call__(self, __other: int) -> _2Tuple[int_]: ...
@overload
def __call__(self, __other: float) -> _2Tuple[floating[Union[_NBit1, _NBitDouble]]]: ...
def __call__(self, __other: float) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ...
@overload
def __call__(self, __other: _IntType) -> _2Tuple[_IntType]: ...
@overload
Expand All @@ -144,34 +144,34 @@ class _IntTrueDiv(Protocol[_NBit1]):
@overload
def __call__(self, __other: bool) -> floating[_NBit1]: ...
@overload
def __call__(self, __other: int) -> floating[Union[_NBit1, _NBitInt]]: ...
def __call__(self, __other: int) -> floating[_NBit1 | _NBitInt]: ...
@overload
def __call__(self, __other: float) -> floating[Union[_NBit1, _NBitDouble]]: ...
def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ...
@overload
def __call__(
self, __other: complex
) -> complexfloating[Union[_NBit1, _NBitDouble], Union[_NBit1, _NBitDouble]]: ...
) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ...
@overload
def __call__(self, __other: integer[_NBit2]) -> floating[Union[_NBit1, _NBit2]]: ...
def __call__(self, __other: integer[_NBit2]) -> floating[_NBit1 | _NBit2]: ...

class _UnsignedIntOp(Protocol[_NBit1]):
# NOTE: `uint64 + signedinteger -> float64`
@overload
def __call__(self, __other: bool) -> unsignedinteger[_NBit1]: ...
@overload
def __call__(
self, __other: Union[int, signedinteger[Any]]
self, __other: int | signedinteger[Any]
) -> Any: ...
@overload
def __call__(self, __other: float) -> floating[Union[_NBit1, _NBitDouble]]: ...
def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ...
@overload
def __call__(
self, __other: complex
) -> complexfloating[Union[_NBit1, _NBitDouble], Union[_NBit1, _NBitDouble]]: ...
) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ...
@overload
def __call__(
self, __other: unsignedinteger[_NBit2]
) -> unsignedinteger[Union[_NBit1, _NBit2]]: ...
) -> unsignedinteger[_NBit1 | _NBit2]: ...

class _UnsignedIntBitOp(Protocol[_NBit1]):
@overload
Expand All @@ -183,135 +183,135 @@ def __call__(self, __other: signedinteger[Any]) -> signedinteger[Any]: ...
@overload
def __call__(
self, __other: unsignedinteger[_NBit2]
) -> unsignedinteger[Union[_NBit1, _NBit2]]: ...
) -> unsignedinteger[_NBit1 | _NBit2]: ...

class _UnsignedIntMod(Protocol[_NBit1]):
@overload
def __call__(self, __other: bool) -> unsignedinteger[_NBit1]: ...
@overload
def __call__(
self, __other: Union[int, signedinteger[Any]]
self, __other: int | signedinteger[Any]
) -> Any: ...
@overload
def __call__(self, __other: float) -> floating[Union[_NBit1, _NBitDouble]]: ...
def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ...
@overload
def __call__(
self, __other: unsignedinteger[_NBit2]
) -> unsignedinteger[Union[_NBit1, _NBit2]]: ...
) -> unsignedinteger[_NBit1 | _NBit2]: ...

class _UnsignedIntDivMod(Protocol[_NBit1]):
@overload
def __call__(self, __other: bool) -> _2Tuple[signedinteger[_NBit1]]: ...
@overload
def __call__(
self, __other: Union[int, signedinteger[Any]]
self, __other: int | signedinteger[Any]
) -> _2Tuple[Any]: ...
@overload
def __call__(self, __other: float) -> _2Tuple[floating[Union[_NBit1, _NBitDouble]]]: ...
def __call__(self, __other: float) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ...
@overload
def __call__(
self, __other: unsignedinteger[_NBit2]
) -> _2Tuple[unsignedinteger[Union[_NBit1, _NBit2]]]: ...
) -> _2Tuple[unsignedinteger[_NBit1 | _NBit2]]: ...

class _SignedIntOp(Protocol[_NBit1]):
@overload
def __call__(self, __other: bool) -> signedinteger[_NBit1]: ...
@overload
def __call__(self, __other: int) -> signedinteger[Union[_NBit1, _NBitInt]]: ...
def __call__(self, __other: int) -> signedinteger[_NBit1 | _NBitInt]: ...
@overload
def __call__(self, __other: float) -> floating[Union[_NBit1, _NBitDouble]]: ...
def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ...
@overload
def __call__(
self, __other: complex
) -> complexfloating[Union[_NBit1, _NBitDouble], Union[_NBit1, _NBitDouble]]: ...
) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ...
@overload
def __call__(
self, __other: signedinteger[_NBit2]
) -> signedinteger[Union[_NBit1, _NBit2]]: ...
) -> signedinteger[_NBit1 | _NBit2]: ...

class _SignedIntBitOp(Protocol[_NBit1]):
@overload
def __call__(self, __other: bool) -> signedinteger[_NBit1]: ...
@overload
def __call__(self, __other: int) -> signedinteger[Union[_NBit1, _NBitInt]]: ...
def __call__(self, __other: int) -> signedinteger[_NBit1 | _NBitInt]: ...
@overload
def __call__(
self, __other: signedinteger[_NBit2]
) -> signedinteger[Union[_NBit1, _NBit2]]: ...
) -> signedinteger[_NBit1 | _NBit2]: ...

class _SignedIntMod(Protocol[_NBit1]):
@overload
def __call__(self, __other: bool) -> signedinteger[_NBit1]: ...
@overload
def __call__(self, __other: int) -> signedinteger[Union[_NBit1, _NBitInt]]: ...
def __call__(self, __other: int) -> signedinteger[_NBit1 | _NBitInt]: ...
@overload
def __call__(self, __other: float) -> floating[Union[_NBit1, _NBitDouble]]: ...
def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ...
@overload
def __call__(
self, __other: signedinteger[_NBit2]
) -> signedinteger[Union[_NBit1, _NBit2]]: ...
) -> signedinteger[_NBit1 | _NBit2]: ...

class _SignedIntDivMod(Protocol[_NBit1]):
@overload
def __call__(self, __other: bool) -> _2Tuple[signedinteger[_NBit1]]: ...
@overload
def __call__(self, __other: int) -> _2Tuple[signedinteger[Union[_NBit1, _NBitInt]]]: ...
def __call__(self, __other: int) -> _2Tuple[signedinteger[_NBit1 | _NBitInt]]: ...
@overload
def __call__(self, __other: float) -> _2Tuple[floating[Union[_NBit1, _NBitDouble]]]: ...
def __call__(self, __other: float) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ...
@overload
def __call__(
self, __other: signedinteger[_NBit2]
) -> _2Tuple[signedinteger[Union[_NBit1, _NBit2]]]: ...
) -> _2Tuple[signedinteger[_NBit1 | _NBit2]]: ...

class _FloatOp(Protocol[_NBit1]):
@overload
def __call__(self, __other: bool) -> floating[_NBit1]: ...
@overload
def __call__(self, __other: int) -> floating[Union[_NBit1, _NBitInt]]: ...
def __call__(self, __other: int) -> floating[_NBit1 | _NBitInt]: ...
@overload
def __call__(self, __other: float) -> floating[Union[_NBit1, _NBitDouble]]: ...
def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ...
@overload
def __call__(
self, __other: complex
) -> complexfloating[Union[_NBit1, _NBitDouble], Union[_NBit1, _NBitDouble]]: ...
) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ...
@overload
def __call__(
self, __other: Union[integer[_NBit2], floating[_NBit2]]
) -> floating[Union[_NBit1, _NBit2]]: ...
self, __other: integer[_NBit2] | floating[_NBit2]
) -> floating[_NBit1 | _NBit2]: ...

class _FloatMod(Protocol[_NBit1]):
@overload
def __call__(self, __other: bool) -> floating[_NBit1]: ...
@overload
def __call__(self, __other: int) -> floating[Union[_NBit1, _NBitInt]]: ...
def __call__(self, __other: int) -> floating[_NBit1 | _NBitInt]: ...
@overload
def __call__(self, __other: float) -> floating[Union[_NBit1, _NBitDouble]]: ...
def __call__(self, __other: float) -> floating[_NBit1 | _NBitDouble]: ...
@overload
def __call__(
self, __other: Union[integer[_NBit2], floating[_NBit2]]
) -> floating[Union[_NBit1, _NBit2]]: ...
self, __other: integer[_NBit2] | floating[_NBit2]
) -> floating[_NBit1 | _NBit2]: ...

class _FloatDivMod(Protocol[_NBit1]):
@overload
def __call__(self, __other: bool) -> _2Tuple[floating[_NBit1]]: ...
@overload
def __call__(self, __other: int) -> _2Tuple[floating[Union[_NBit1, _NBitInt]]]: ...
def __call__(self, __other: int) -> _2Tuple[floating[_NBit1 | _NBitInt]]: ...
@overload
def __call__(self, __other: float) -> _2Tuple[floating[Union[_NBit1, _NBitDouble]]]: ...
def __call__(self, __other: float) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ...
@overload
def __call__(
self, __other: Union[integer[_NBit2], floating[_NBit2]]
) -> _2Tuple[floating[Union[_NBit1, _NBit2]]]: ...
self, __other: integer[_NBit2] | floating[_NBit2]
) -> _2Tuple[floating[_NBit1 | _NBit2]]: ...

class _ComplexOp(Protocol[_NBit1]):
@overload
def __call__(self, __other: bool) -> complexfloating[_NBit1, _NBit1]: ...
@overload
def __call__(self, __other: int) -> complexfloating[Union[_NBit1, _NBitInt], Union[_NBit1, _NBitInt]]: ...
def __call__(self, __other: int) -> complexfloating[_NBit1 | _NBitInt, _NBit1 | _NBitInt]: ...
@overload
def __call__(
self, __other: Union[float, complex]
) -> complexfloating[Union[_NBit1, _NBitDouble], Union[_NBit1, _NBitDouble]]: ...
self, __other: complex
) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ...
@overload
def __call__(
self,
Expand All @@ -320,7 +320,7 @@ def __call__(
floating[_NBit2],
complexfloating[_NBit2, _NBit2],
]
) -> complexfloating[Union[_NBit1, _NBit2], Union[_NBit1, _NBit2]]: ...
) -> complexfloating[_NBit1 | _NBit2, _NBit1 | _NBit2]: ...

class _NumberOp(Protocol):
def __call__(self, __other: _NumberLike_co) -> Any: ...
Expand Down
Loading
0