Skip to content

Commit 0dd925f

Browse files
committed
TYP: sprinkle some TypeAliases and Finals around
1 parent bca9c0c commit 0dd925f

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

array_api_compat/common/_fft.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from __future__ import annotations
22

33
from collections.abc import Sequence
4-
from typing import Literal
4+
from typing import Literal, TypeAlias
55

66
from ._typing import Array, Device, DType, Namespace
77

8-
_Norm = Literal["backward", "ortho", "forward"]
8+
_Norm: TypeAlias = Literal["backward", "ortho", "forward"]
99

1010
# Note: NumPy fft functions improperly upcast float32 and complex64 to
1111
# complex128, which is why we require wrapping them all here.

array_api_compat/common/_typing.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from types import ModuleType as Namespace
4-
from typing import Any, Protocol, TypeVar
4+
from typing import Any, Protocol, TypeAlias, TypeVar
55

66
__all__ = [
77
"Array",
@@ -30,7 +30,7 @@ class HasShape(Protocol[_T_co]):
3030
def shape(self, /) -> _T_co: ...
3131

3232

33-
SupportsBufferProtocol = Any
34-
Array = Any
35-
Device = Any
36-
DType = Any
33+
SupportsBufferProtocol: TypeAlias = Any
34+
Array: TypeAlias = Any
35+
Device: TypeAlias = Any
36+
DType: TypeAlias = Any

array_api_compat/numpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@
3232
except ImportError:
3333
pass
3434

35-
__array_api_version__ = "2024.12"
35+
__array_api_version__: Final = "2024.12"

array_api_compat/numpy/_typing.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
__all__ = ["Array", "DType", "Device"]
44
_all_ignore = ["np"]
55

6-
from typing import TYPE_CHECKING, Any, Literal
6+
from typing import TYPE_CHECKING, Any, Literal, TypeAlias
77

88
import numpy as np
99

10-
Device = Literal["cpu"]
10+
Device: TypeAlias = Literal["cpu"]
11+
1112
if TYPE_CHECKING:
12-
from typing_extensions import TypeAlias
1313

1414
# NumPy 1.x on Python 3.10 fails to parse np.dtype[]
1515
DType: TypeAlias = np.dtype[
@@ -22,5 +22,5 @@
2222
]
2323
Array: TypeAlias = np.ndarray[Any, DType]
2424
else:
25-
DType = np.dtype
26-
Array = np.ndarray
25+
DType: TypeAlias = np.dtype
26+
Array: TypeAlias = np.ndarray

0 commit comments

Comments
 (0)