Skip to content

Commit a5be256

Browse files
committed
TYP: Annotate type aliases without annotation
1 parent ab5064c commit a5be256

20 files changed

+51
-63
lines changed

numpy/_core/_asarray.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
from collections.abc import Iterable
2-
from typing import Any, TypeVar, overload, Literal
2+
from typing import Any, TypeAlias, TypeVar, overload, Literal
33

44
from numpy._typing import NDArray, DTypeLike, _SupportsArrayFunc
55

66
_ArrayType = TypeVar("_ArrayType", bound=NDArray[Any])
77

8-
_Requirements = Literal[
8+
_Requirements: TypeAlias = Literal[
99
"C", "C_CONTIGUOUS", "CONTIGUOUS",
1010
"F", "F_CONTIGUOUS", "FORTRAN",
1111
"A", "ALIGNED",
1212
"W", "WRITEABLE",
1313
"O", "OWNDATA"
1414
]
15-
_E = Literal["E", "ENSUREARRAY"]
16-
_RequirementsWithE = _Requirements | _E
15+
_E: TypeAlias = Literal["E", "ENSUREARRAY"]
16+
_RequirementsWithE: TypeAlias = _Requirements | _E
1717

1818
@overload
1919
def require(

numpy/_core/_ufunc_config.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from collections.abc import Callable
2-
from typing import Any, Literal, TypedDict
2+
from typing import Any, Literal, TypeAlias, TypedDict
33

44
from numpy import _SupportsWrite
55

6-
_ErrKind = Literal["ignore", "warn", "raise", "call", "print", "log"]
7-
_ErrFunc = Callable[[str, int], Any]
6+
_ErrKind: TypeAlias = Literal["ignore", "warn", "raise", "call", "print", "log"]
7+
_ErrFunc: TypeAlias = Callable[[str, int], Any]
88

99
class _ErrDict(TypedDict):
1010
divide: _ErrKind

numpy/_core/arrayprint.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections.abc import Callable
2-
from typing import Any, Literal, TypedDict, SupportsIndex
2+
from typing import Any, Literal, TypeAlias, TypedDict, SupportsIndex
33

44
# Using a private class is by no means ideal, but it is simply a consequence
55
# of a `contextlib.context` returning an instance of aforementioned class
@@ -18,7 +18,7 @@ from numpy import (
1818
)
1919
from numpy._typing import NDArray, _CharLike_co, _FloatLike_co
2020

21-
_FloatMode = Literal["fixed", "unique", "maxprec", "maxprec_equal"]
21+
_FloatMode: TypeAlias = Literal["fixed", "unique", "maxprec", "maxprec_equal"]
2222

2323
class _FormatDict(TypedDict, total=False):
2424
bool: Callable[[np.bool], str]

numpy/_core/einsumfunc.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections.abc import Sequence
2-
from typing import TypeVar, Any, overload, Literal
2+
from typing import TypeAlias, TypeVar, Any, overload, Literal
33

44
import numpy as np
55
from numpy import number, _OrderKACF
@@ -25,9 +25,9 @@ _ArrayType = TypeVar(
2525
bound=NDArray[np.bool | number[Any]],
2626
)
2727

28-
_OptimizeKind = None | bool | Literal["greedy", "optimal"] | Sequence[Any]
29-
_CastingSafe = Literal["no", "equiv", "safe", "same_kind"]
30-
_CastingUnsafe = Literal["unsafe"]
28+
_OptimizeKind: TypeAlias = bool | Literal["greedy", "optimal"] | Sequence[Any] | None
29+
_CastingSafe: TypeAlias = Literal["no", "equiv", "safe", "same_kind"]
30+
_CastingUnsafe: TypeAlias = Literal["unsafe"]
3131

3232
__all__: list[str]
3333

numpy/_core/multiarray.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ _1DArray: TypeAlias = ndarray[tuple[_SizeType], dtype[_SCT]]
112112
_Array: TypeAlias = ndarray[_ShapeType, dtype[_SCT]]
113113

114114
# Valid time units
115-
_UnitKind = L[
115+
_UnitKind: TypeAlias = L[
116116
"Y",
117117
"M",
118118
"D",
@@ -126,7 +126,7 @@ _UnitKind = L[
126126
"fs",
127127
"as",
128128
]
129-
_RollKind = L[ # `raise` is deliberately excluded
129+
_RollKind: TypeAlias = L[ # `raise` is deliberately excluded
130130
"nat",
131131
"forward",
132132
"following",
@@ -1164,7 +1164,7 @@ def compare_chararrays(
11641164

11651165
def add_docstring(obj: Callable[..., Any], docstring: str, /) -> None: ...
11661166

1167-
_GetItemKeys = L[
1167+
_GetItemKeys: TypeAlias = L[
11681168
"C", "CONTIGUOUS", "C_CONTIGUOUS",
11691169
"F", "FORTRAN", "F_CONTIGUOUS",
11701170
"W", "WRITEABLE",
@@ -1177,7 +1177,7 @@ _GetItemKeys = L[
11771177
"FNC",
11781178
"FORC",
11791179
]
1180-
_SetItemKeys = L[
1180+
_SetItemKeys: TypeAlias = L[
11811181
"A", "ALIGNED",
11821182
"W", "WRITEABLE",
11831183
"X", "WRITEBACKIFCOPY",

numpy/_core/numeric.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ from collections.abc import Callable, Sequence
22
from typing import (
33
Any,
44
Final,
5+
TypeAlias,
56
overload,
67
TypeVar,
78
Literal as L,
@@ -61,7 +62,7 @@ _ArrayType = TypeVar("_ArrayType", bound=np.ndarray[Any, Any])
6162
_SizeType = TypeVar("_SizeType", bound=int)
6263
_ShapeType = TypeVar("_ShapeType", bound=tuple[int, ...])
6364

64-
_CorrelateMode = L["valid", "same", "full"]
65+
_CorrelateMode: TypeAlias = L["valid", "same", "full"]
6566

6667
__all__: list[str]
6768

numpy/_core/records.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ from collections.abc import Sequence, Iterable
33
from types import EllipsisType
44
from typing import (
55
Any,
6+
TypeAlias,
67
TypeVar,
78
overload,
89
Protocol,
@@ -35,7 +36,7 @@ from numpy._typing import (
3536

3637
_SCT = TypeVar("_SCT", bound=generic)
3738

38-
_RecArray = recarray[Any, dtype[_SCT]]
39+
_RecArray: TypeAlias = recarray[Any, dtype[_SCT]]
3940

4041
class _SupportsReadInto(Protocol):
4142
def seek(self, offset: int, whence: int, /) -> object: ...

numpy/ctypeslib.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ from collections.abc import Iterable, Sequence
88
from typing import (
99
Literal as L,
1010
Any,
11+
TypeAlias,
1112
TypeVar,
1213
Generic,
1314
overload,
@@ -72,7 +73,7 @@ _DType = TypeVar("_DType", bound=dtype[Any])
7273
_DTypeOptional = TypeVar("_DTypeOptional", bound=None | dtype[Any])
7374
_SCT = TypeVar("_SCT", bound=generic)
7475

75-
_FlagsKind = L[
76+
_FlagsKind: TypeAlias = L[
7677
'C_CONTIGUOUS', 'CONTIGUOUS', 'C',
7778
'F_CONTIGUOUS', 'FORTRAN', 'F',
7879
'ALIGNED', 'A',

numpy/fft/_pocketfft.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from collections.abc import Sequence
2-
from typing import Literal as L
2+
from typing import Literal as L, TypeAlias
33

44
from numpy import complex128, float64
55
from numpy._typing import ArrayLike, NDArray, _ArrayLikeNumber_co
66

7-
_NormKind = L[None, "backward", "ortho", "forward"]
7+
_NormKind: TypeAlias = L[None, "backward", "ortho", "forward"]
88

99
__all__: list[str]
1010

numpy/lib/_arraypad_impl.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import (
22
Literal as L,
33
Any,
4+
TypeAlias,
45
overload,
56
TypeVar,
67
Protocol,
@@ -27,7 +28,7 @@ class _ModeFunc(Protocol):
2728
/,
2829
) -> None: ...
2930

30-
_ModeKind = L[
31+
_ModeKind: TypeAlias = L[
3132
"constant",
3233
"edge",
3334
"linear_ramp",

0 commit comments

Comments
 (0)