Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions src/array_api_extra/_lib/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import warnings
from collections.abc import Callable, Generator, Iterable, Iterator, Sequence
from typing import (
TYPE_CHECKING,
Any,
ClassVar,
Generic,
Expand All @@ -22,16 +21,7 @@
)

from . import _compat
from ._typing import Array, ArrayNamespace

if TYPE_CHECKING: # pragma: no cover
# TODO import from typing (requires Python >=3.12 and >=3.13)
from typing_extensions import TypeIs, override
else:

def override(func):
return func

from ._typing import Array, ArrayNamespace, TypeIs, override

P = ParamSpec("P")
T = TypeVar("T")
Expand Down
20 changes: 18 additions & 2 deletions src/array_api_extra/_lib/_typing.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
"""Static typing helpers."""
# numpydoc ignore=GL08
"""Static typing helpers — better implementations in the stub file."""

from collections.abc import Callable
from types import ModuleType
from typing import Any

Array = object
ArrayLike = object
ArrayNamespace = ModuleType
DType = object
Device = object
Key = object
GetIndex = object
Graph = object
NumPyObject = object
SchedulerGetCallable = object
SetIndex = object

TypeIs = Any

__all__ = [
"Array",
"ArrayLike",
"ArrayNamespace",
"DType",
"Device",
"GetIndex",
"Graph",
"Key",
"NumPyObject",
"SchedulerGetCallable",
"SetIndex",
"TypeIs",
"override",
]


def override(func: Callable[..., Any]) -> Callable[..., Any]: # numpydoc ignore=GL08
return func
10 changes: 8 additions & 2 deletions src/array_api_extra/_lib/_typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ from types import EllipsisType, ModuleType
from typing import Any, Protocol, TypeAlias

import numpy as np
from dask.typing import Graph, Key, SchedulerGetCallable
from numpy.typing import ArrayLike

# TODO import from typing (requires Python >=3.12)
from typing_extensions import override
# TODO import from typing (requires Python >=3.12 and >=3.13)
from typing_extensions import TypeIs, override

# TODO: use array-api-typing once it is available

Expand Down Expand Up @@ -112,6 +113,11 @@ __all__ = [
"DType",
"Device",
"GetIndex",
"Graph",
"Key",
"NumPyObject",
"SchedulerGetCallable",
"SetIndex",
"TypeIs",
"override",
]
32 changes: 15 additions & 17 deletions src/array_api_extra/testing/_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,22 @@
import warnings
from collections.abc import Callable, Generator, Iterator, Sequence
from types import FunctionType, ModuleType
from typing import TYPE_CHECKING, Any, ParamSpec, TypeVar
from typing import Any, ParamSpec, TypeVar

from .._lib import _compat, _helpers
from .._lib._typing import Array, ArrayNamespace, Device
from .._lib._typing import (
Array,
ArrayNamespace,
Device,
Graph,
Key,
SchedulerGetCallable,
override,
)

if typing.TYPE_CHECKING:
import numpy as np
import pytest

__all__ = [
"assert_close",
Expand All @@ -25,20 +37,6 @@
"patch_lazy_xp_functions",
]

if TYPE_CHECKING: # pragma: no cover
# TODO import override from typing (requires Python >=3.12)
import numpy as np
import pytest
from dask.typing import Graph, Key, SchedulerGetCallable
from typing_extensions import override as _override

else:
# Sphinx hacks
SchedulerGetCallable = object

def _override(func):
return func


__all__ = [
"assert_close",
Expand Down Expand Up @@ -493,7 +491,7 @@ def __init__(self, max_count: int, msg: str) -> None: # numpydoc ignore=GL08
self.max_count = max_count
self.msg = msg

@_override
@override
def __call__(
self, dsk: Graph, keys: Sequence[Key] | Key, **kwargs: Any
) -> Any: # numpydoc ignore=GL08
Expand Down
13 changes: 2 additions & 11 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Iterator
from typing import TYPE_CHECKING, Generic, TypeVar, cast
from typing import Generic, TypeVar, cast

import numpy as np
import pytest
Expand All @@ -18,20 +18,11 @@
pickle_flatten,
pickle_unflatten,
)
from array_api_extra._lib._typing import Array, ArrayNamespace, Device, DType
from array_api_extra._lib._typing import Array, ArrayNamespace, Device, DType, override
from array_api_extra.testing import assert_equal, lazy_xp_function

from .conftest import np_compat

if TYPE_CHECKING: # pragma: no cover
# TODO import from typing (requires Python >=3.12)
from typing_extensions import override
else:

def override(func):
return func


T = TypeVar("T")

# FIXME calls xp.unique_values without size
Expand Down