Skip to content

Commit 3e5fdc0

Browse files
authored
Merge pull request #302 from crusaderky/import_helpers
BUG: Don't import helpers in namespaces
2 parents 9a87e6f + 2c1cb6b commit 3e5fdc0

File tree

7 files changed

+7
-18
lines changed

7 files changed

+7
-18
lines changed

array_api_compat/common/_linalg.py

+2
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,5 @@ def trace(
174174
'svd', 'cholesky', 'matrix_rank', 'pinv', 'matrix_norm',
175175
'matrix_transpose', 'svdvals', 'vecdot', 'vector_norm', 'diagonal',
176176
'trace']
177+
178+
_all_ignore = ['math', 'normalize_axis_tuple', 'get_xp', 'np', 'isdtype']

array_api_compat/cupy/__init__.py

-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88

99
# See the comment in the numpy __init__.py
1010
__import__(__package__ + '.linalg')
11-
1211
__import__(__package__ + '.fft')
1312

14-
from ..common._helpers import * # noqa: F401,F403
15-
1613
__array_api_version__ = '2024.12'

array_api_compat/dask/array/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55

66
__array_api_version__ = '2024.12'
77

8+
# See the comment in the numpy __init__.py
89
__import__(__package__ + '.linalg')
910
__import__(__package__ + '.fft')

array_api_compat/numpy/__init__.py

-9
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,8 @@
1414
# It doesn't overwrite np.linalg from above. The import is generated
1515
# dynamically so that the library can be vendored.
1616
__import__(__package__ + '.linalg')
17-
1817
__import__(__package__ + '.fft')
1918

2019
from .linalg import matrix_transpose, vecdot # noqa: F401
2120

22-
from ..common._helpers import * # noqa: F403
23-
24-
try:
25-
# Used in asarray(). Not present in older versions.
26-
from numpy import _CopyMode # noqa: F401
27-
except ImportError:
28-
pass
29-
3021
__array_api_version__ = '2024.12'

array_api_compat/numpy/_aliases.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def asarray(
8888
*,
8989
dtype: Optional[DType] = None,
9090
device: Optional[Device] = None,
91-
copy: "Optional[Union[bool, np._CopyMode]]" = None,
91+
copy: Optional[Union[bool, np._CopyMode]] = None,
9292
**kwargs,
9393
) -> Array:
9494
"""

array_api_compat/torch/__init__.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@
99
or 'cpu' in n
1010
or 'backward' in n):
1111
continue
12-
exec(n + ' = torch.' + n)
12+
exec(f"{n} = torch.{n}")
13+
del n
1314

1415
# These imports may overwrite names from the import * above.
1516
from ._aliases import * # noqa: F403
1617

1718
# See the comment in the numpy __init__.py
1819
__import__(__package__ + '.linalg')
19-
2020
__import__(__package__ + '.fft')
2121

22-
from ..common._helpers import * # noqa: F403
23-
2422
__array_api_version__ = '2024.12'

tests/test_common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def test_asarray_copy(library):
276276
is_lib_func = globals()[is_array_functions[library]]
277277
all = xp.all if library != 'dask.array' else lambda x: xp.all(x).compute()
278278

279-
if library == 'numpy' and xp.__version__[0] < '2' and not hasattr(xp, '_CopyMode') :
279+
if library == 'numpy' and xp.__version__[0] < '2' and not hasattr(np, "_CopyMode"):
280280
supports_copy_false_other_ns = False
281281
supports_copy_false_same_ns = False
282282
elif library == 'cupy':

0 commit comments

Comments
 (0)