Skip to content

Commit ec72825

Browse files
committed
TYP: it's a bad idea to import TypeAlias from typing on python<3.10
1 parent 014385f commit ec72825

File tree

4 files changed

+10
-17
lines changed

4 files changed

+10
-17
lines changed

array_api_compat/common/_fft.py

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,7 @@
1212
import math
1313
import sys
1414
import warnings
15-
from typing import (
16-
TYPE_CHECKING,
17-
Any,
18-
Literal,
19-
SupportsIndex,
20-
TypeAlias,
21-
TypeGuard,
22-
cast,
23-
overload,
24-
)
15+
from typing import TYPE_CHECKING, Any, Literal, SupportsIndex, TypeGuard, cast, overload
2516

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

@@ -35,7 +26,7 @@
3526
import numpy.typing as npt
3627
import sparse # pyright: ignore[reportMissingTypeStubs]
3728
import torch
38-
from typing_extensions import TypeIs, TypeVar
29+
from typing_extensions import TypeAlias, TypeIs, TypeVar
3930

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

array_api_compat/numpy/_aliases.py

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 2 deletions
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.10 fails to parse np.dtype[]
1315
DType: TypeAlias = np.dtype[
1416
np.bool_

0 commit comments

Comments
 (0)