Skip to content

Commit b5aa2ae

Browse files
committed
TYP: it's a bad idea to import TypeAlias from typing on python<3.10
1 parent 6c5c350 commit b5aa2ae

File tree

4 files changed

+10
-17
lines changed

4 files changed

+10
-17
lines changed

array_api_compat/common/_fft.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from collections.abc import Sequence
2-
from typing import Literal, TypeAlias
2+
from typing import Literal
33

44
from ._typing import Array, Device, DType, Namespace
55

6-
_Norm: TypeAlias = Literal["backward", "ortho", "forward"]
6+
_Norm = Literal["backward", "ortho", "forward"]
77

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

array_api_compat/common/_helpers.py

+2-11
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,7 @@
1111
import math
1212
import sys
1313
import warnings
14-
from typing import (
15-
TYPE_CHECKING,
16-
Any,
17-
Literal,
18-
SupportsIndex,
19-
TypeAlias,
20-
TypeGuard,
21-
cast,
22-
overload,
23-
)
14+
from typing import TYPE_CHECKING, Any, Literal, SupportsIndex, TypeGuard, cast, overload
2415

2516
from ._typing import Array, Device, HasShape, Namespace, SupportsArrayNamespace
2617

@@ -34,7 +25,7 @@
3425
import numpy.typing as npt
3526
import sparse # pyright: ignore[reportMissingTypeStubs]
3627
import torch
37-
from typing_extensions import TypeIs, TypeVar
28+
from typing_extensions import TypeAlias, TypeIs, TypeVar
3829

3930
_SizeT = TypeVar("_SizeT", bound=int | None)
4031

array_api_compat/numpy/_aliases.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
from ._typing import Array, Device, DType
1414

1515
if TYPE_CHECKING:
16-
from typing import Any, Literal, TypeAlias
16+
from typing import Any, Literal
1717

18-
from typing_extensions import Buffer, TypeIs
18+
from typing_extensions import Buffer, TypeAlias, TypeIs
1919

2020
_Copy: TypeAlias = py_bool | Literal[2] | np._CopyMode
2121

array_api_compat/numpy/_typing.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
__all__ = ["Array", "DType", "Device"]
44
_all_ignore = ["np"]
55

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

88
import numpy as np
99

10-
Device: TypeAlias = Literal["cpu"]
10+
Device = Literal["cpu"]
1111
if TYPE_CHECKING:
12+
from typing_extensions import TypeAlias
13+
1214
# NumPy 1.x on Python 3.9 and 3.10 fails to parse np.dtype[]
1315
DType: TypeAlias = np.dtype[
1416
np.bool_

0 commit comments

Comments
 (0)