Skip to content

Commit 6789a74

Browse files
committed
Move some imports out of functions to the top of the file
Some of the imports in the array API module have to be inside functions to avoid circular imports, but these ones did not.
1 parent bc20d33 commit 6789a74

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

numpy/array_api/_array_object.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@
1919
from enum import IntEnum
2020
from ._creation_functions import asarray
2121
from ._dtypes import (_all_dtypes, _boolean_dtypes, _integer_dtypes,
22-
_integer_or_boolean_dtypes, _floating_dtypes, _numeric_dtypes)
22+
_integer_or_boolean_dtypes, _floating_dtypes,
23+
_numeric_dtypes, _result_type, _dtype_categories)
2324

2425
from typing import TYPE_CHECKING, Optional, Tuple, Union
2526
if TYPE_CHECKING:
2627
from ._typing import PyCapsule, Device, Dtype
2728

2829
import numpy as np
2930

31+
from numpy import array_api
32+
3033
class Array:
3134
"""
3235
n-d array object for the array API namespace.
@@ -98,7 +101,6 @@ def _check_allowed_dtypes(self, other, dtype_category, op):
98101
if other is NotImplemented:
99102
return other
100103
"""
101-
from ._dtypes import _result_type, _dtype_categories
102104

103105
if self.dtype not in _dtype_categories[dtype_category]:
104106
raise TypeError(f'Only {dtype_category} dtypes are allowed in {op}')
@@ -338,7 +340,6 @@ def __and__(self: Array, other: Union[int, bool, Array], /) -> Array:
338340
def __array_namespace__(self: Array, /, *, api_version: Optional[str] = None) -> object:
339341
if api_version is not None and not api_version.startswith('2021.'):
340342
raise ValueError(f"Unrecognized array API version: {api_version!r}")
341-
from numpy import array_api
342343
return array_api
343344

344345
def __bool__(self: Array, /) -> bool:

0 commit comments

Comments
 (0)