uarray 0.9.2__cp313-cp313-win32.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- uarray/.coveragerc +9 -0
- uarray/__init__.py +118 -0
- uarray/_backend.py +800 -0
- uarray/_typing.pyi +65 -0
- uarray/_uarray.cp313-win32.pyd +0 -0
- uarray/_uarray.pyi +131 -0
- uarray/_version.py +16 -0
- uarray/conftest.py +11 -0
- uarray/py.typed +0 -0
- uarray/pytest.ini +3 -0
- uarray/tests/__init__.py +0 -0
- uarray/tests/example_helpers.py +46 -0
- uarray/tests/test_uarray.py +580 -0
- uarray-0.9.2.dist-info/LICENSE +29 -0
- uarray-0.9.2.dist-info/METADATA +88 -0
- uarray-0.9.2.dist-info/RECORD +18 -0
- uarray-0.9.2.dist-info/WHEEL +5 -0
- uarray-0.9.2.dist-info/top_level.txt +1 -0
uarray/_typing.pyi
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Helper module with various typing-related utilities."""
|
|
2
|
+
|
|
3
|
+
import functools
|
|
4
|
+
from collections.abc import Callable
|
|
5
|
+
from typing import Any, Protocol, TypeVar, Iterable, type_check_only
|
|
6
|
+
|
|
7
|
+
import uarray
|
|
8
|
+
|
|
9
|
+
_T = TypeVar("_T")
|
|
10
|
+
_TT = TypeVar("_TT", bound=type[Any])
|
|
11
|
+
_T_co = TypeVar("_T_co", covariant=True)
|
|
12
|
+
|
|
13
|
+
@type_check_only
|
|
14
|
+
class _PySequence(Protocol[_T_co]):
|
|
15
|
+
def __len__(self) -> int: ...
|
|
16
|
+
def __getitem__(self, key: int, /) -> _T_co: ...
|
|
17
|
+
|
|
18
|
+
@type_check_only
|
|
19
|
+
class _SupportsUA(Protocol):
|
|
20
|
+
@property
|
|
21
|
+
def __ua_domain__(self) -> str | _PySequence[str]: ...
|
|
22
|
+
@property
|
|
23
|
+
def __ua_cache__(self) -> dict[Any, Any]: ...
|
|
24
|
+
def __ua_convert__(
|
|
25
|
+
self,
|
|
26
|
+
dispatchables: tuple[uarray.Dispatchable[Any, Any], ...],
|
|
27
|
+
coerce: bool,
|
|
28
|
+
/,
|
|
29
|
+
) -> Iterable[Any]: ...
|
|
30
|
+
|
|
31
|
+
@type_check_only
|
|
32
|
+
class _PartialDispatchable(functools.partial[uarray.Dispatchable[Any, _TT]]):
|
|
33
|
+
func: type[uarray.Dispatchable[Any, _TT]]
|
|
34
|
+
args: tuple[_TT]
|
|
35
|
+
def __call__( # type: ignore[override]
|
|
36
|
+
self,
|
|
37
|
+
value: _T,
|
|
38
|
+
coercible: bool = ...,
|
|
39
|
+
) -> uarray.Dispatchable[_T, _TT]: ...
|
|
40
|
+
|
|
41
|
+
_ReplacerFunc = Callable[
|
|
42
|
+
[
|
|
43
|
+
tuple[Any, ...],
|
|
44
|
+
dict[str, Any],
|
|
45
|
+
tuple[uarray.Dispatchable[Any, Any], ...],
|
|
46
|
+
],
|
|
47
|
+
tuple[tuple[Any, ...], dict[str, Any]],
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
_PyGlobalDict = dict[
|
|
51
|
+
str,
|
|
52
|
+
tuple[
|
|
53
|
+
tuple[_T | None, bool, bool],
|
|
54
|
+
list[_T],
|
|
55
|
+
bool,
|
|
56
|
+
],
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
_PyLocalDict = dict[
|
|
60
|
+
str,
|
|
61
|
+
tuple[
|
|
62
|
+
list[_T],
|
|
63
|
+
list[tuple[_T, bool, bool]],
|
|
64
|
+
],
|
|
65
|
+
]
|
|
Binary file
|
uarray/_uarray.pyi
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""Annotations for the ``uarray._uarray`` extension module."""
|
|
2
|
+
|
|
3
|
+
import types
|
|
4
|
+
from collections.abc import Callable, Iterable
|
|
5
|
+
from typing import Any, final, overload, Generic
|
|
6
|
+
|
|
7
|
+
# TODO: Import from `typing` once `uarray` requires Python >= 3.10
|
|
8
|
+
from typing_extensions import ParamSpec
|
|
9
|
+
|
|
10
|
+
import uarray
|
|
11
|
+
from uarray._typing import (
|
|
12
|
+
_PyGlobalDict,
|
|
13
|
+
_PyLocalDict,
|
|
14
|
+
_ReplacerFunc,
|
|
15
|
+
_SupportsUA,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
_P = ParamSpec("_P")
|
|
19
|
+
|
|
20
|
+
class BackendNotImplementedError(NotImplementedError): ...
|
|
21
|
+
|
|
22
|
+
@final
|
|
23
|
+
class _SkipBackendContext:
|
|
24
|
+
def __init__(self, backend: _SupportsUA) -> None: ...
|
|
25
|
+
def __enter__(self) -> None: ...
|
|
26
|
+
def __exit__(
|
|
27
|
+
self,
|
|
28
|
+
exc_type: type[BaseException] | None,
|
|
29
|
+
exc_value: BaseException | None,
|
|
30
|
+
traceback: types.TracebackType | None,
|
|
31
|
+
/,
|
|
32
|
+
) -> None: ...
|
|
33
|
+
def _pickle(self) -> tuple[_SupportsUA]: ...
|
|
34
|
+
|
|
35
|
+
@final
|
|
36
|
+
class _SetBackendContext:
|
|
37
|
+
def __init__(
|
|
38
|
+
self,
|
|
39
|
+
backend: _SupportsUA,
|
|
40
|
+
coerce: bool = ...,
|
|
41
|
+
only: bool = ...,
|
|
42
|
+
) -> None: ...
|
|
43
|
+
def __enter__(self) -> None: ...
|
|
44
|
+
def __exit__(
|
|
45
|
+
self,
|
|
46
|
+
exc_type: type[BaseException] | None,
|
|
47
|
+
exc_value: BaseException | None,
|
|
48
|
+
traceback: types.TracebackType | None,
|
|
49
|
+
/,
|
|
50
|
+
) -> None: ...
|
|
51
|
+
def _pickle(self) -> tuple[_SupportsUA, bool, bool]: ...
|
|
52
|
+
|
|
53
|
+
# NOTE: Parametrize w.r.t. `__ua_domain__` when returning, but use `Any`
|
|
54
|
+
# when used as argument type. Due to lists being invariant the `__ua_domain__`
|
|
55
|
+
# protocol will likelly be disruptivelly strict in the latter case, hence the
|
|
56
|
+
# usage of `Any` as an escape hatch.
|
|
57
|
+
@final
|
|
58
|
+
class _BackendState:
|
|
59
|
+
def _pickle(self) -> tuple[
|
|
60
|
+
_PyGlobalDict[_SupportsUA],
|
|
61
|
+
_PyLocalDict[_SupportsUA],
|
|
62
|
+
bool,
|
|
63
|
+
]: ...
|
|
64
|
+
@classmethod
|
|
65
|
+
def _unpickle(
|
|
66
|
+
cls,
|
|
67
|
+
py_global: _PyGlobalDict[Any],
|
|
68
|
+
py_locals: _PyLocalDict[Any],
|
|
69
|
+
use_thread_local_globals: bool,
|
|
70
|
+
/,
|
|
71
|
+
) -> _BackendState: ...
|
|
72
|
+
|
|
73
|
+
# TODO: Remove the `type: ignore` once python/mypy#12033 has been bug fixed
|
|
74
|
+
@final # type: ignore[arg-type]
|
|
75
|
+
class _Function(Generic[_P]):
|
|
76
|
+
def __init__(
|
|
77
|
+
self,
|
|
78
|
+
extractor: Callable[_P, tuple[uarray.Dispatchable[Any, Any], ...]],
|
|
79
|
+
replacer: None | _ReplacerFunc,
|
|
80
|
+
domain: str,
|
|
81
|
+
def_args: tuple[Any, ...],
|
|
82
|
+
def_kwargs: dict[str, Any],
|
|
83
|
+
def_impl: None | Callable[..., Any],
|
|
84
|
+
) -> None: ...
|
|
85
|
+
def __repr__(self) -> str: ...
|
|
86
|
+
def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> Any: ...
|
|
87
|
+
@overload
|
|
88
|
+
def __get__(self, obj: None, type: type[Any]) -> _Function[_P]: ...
|
|
89
|
+
@overload
|
|
90
|
+
def __get__(
|
|
91
|
+
self, obj: object, type: None | type[Any] = ...
|
|
92
|
+
) -> types.MethodType: ...
|
|
93
|
+
@property
|
|
94
|
+
def arg_extractor(self) -> Callable[_P, tuple[uarray.Dispatchable[Any, Any], ...]]: ...
|
|
95
|
+
@property
|
|
96
|
+
def arg_replacer(self) -> None | _ReplacerFunc: ...
|
|
97
|
+
@property
|
|
98
|
+
def default(self) -> None | Callable[..., Any]: ...
|
|
99
|
+
@property
|
|
100
|
+
def domain(self) -> str: ...
|
|
101
|
+
# NOTE: These attributes are dynamically inserted by
|
|
102
|
+
# `uarray.generate_multimethod` via a `functools.update_wrapper` call
|
|
103
|
+
__module__: str
|
|
104
|
+
__name__: str
|
|
105
|
+
__qualname__: str
|
|
106
|
+
__doc__: None | str
|
|
107
|
+
__wrapped__: Callable[_P, tuple[uarray.Dispatchable[Any, Any], ...]]
|
|
108
|
+
__annotations__: dict[str, Any]
|
|
109
|
+
|
|
110
|
+
def set_global_backend(
|
|
111
|
+
backend: _SupportsUA,
|
|
112
|
+
coerce: bool = ...,
|
|
113
|
+
only: bool = ...,
|
|
114
|
+
try_last: bool = ...,
|
|
115
|
+
/,
|
|
116
|
+
) -> None: ...
|
|
117
|
+
def clear_backends(
|
|
118
|
+
domain: None | str,
|
|
119
|
+
registered: bool = ...,
|
|
120
|
+
global_: bool = ...,
|
|
121
|
+
/,
|
|
122
|
+
) -> None: ...
|
|
123
|
+
def determine_backend(
|
|
124
|
+
domain_object: str,
|
|
125
|
+
dispatchables: Iterable[uarray.Dispatchable[Any, Any]],
|
|
126
|
+
coerce: bool,
|
|
127
|
+
/,
|
|
128
|
+
) -> _SupportsUA: ...
|
|
129
|
+
def register_backend(backend: _SupportsUA, /) -> None: ...
|
|
130
|
+
def get_state() -> _BackendState: ...
|
|
131
|
+
def set_state(arg: _BackendState, reset_allowed: bool = ..., /) -> None: ...
|
uarray/_version.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# file generated by setuptools_scm
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
TYPE_CHECKING = False
|
|
4
|
+
if TYPE_CHECKING:
|
|
5
|
+
from typing import Tuple, Union
|
|
6
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
7
|
+
else:
|
|
8
|
+
VERSION_TUPLE = object
|
|
9
|
+
|
|
10
|
+
version: str
|
|
11
|
+
__version__: str
|
|
12
|
+
__version_tuple__: VERSION_TUPLE
|
|
13
|
+
version_tuple: VERSION_TUPLE
|
|
14
|
+
|
|
15
|
+
__version__ = version = '0.9.2'
|
|
16
|
+
__version_tuple__ = version_tuple = (0, 9, 2)
|
uarray/conftest.py
ADDED
uarray/py.typed
ADDED
|
File without changes
|
uarray/pytest.ini
ADDED
uarray/tests/__init__.py
ADDED
|
File without changes
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import uarray as ua
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class _TypedBackend:
|
|
5
|
+
__ua_domain__ = "ua_examples"
|
|
6
|
+
|
|
7
|
+
def __init__(self, *my_types):
|
|
8
|
+
self.my_types = my_types
|
|
9
|
+
|
|
10
|
+
def __ua_convert__(self, dispatchables, coerce):
|
|
11
|
+
if not all(type(d.value) in self.my_types for d in dispatchables):
|
|
12
|
+
return NotImplemented
|
|
13
|
+
return tuple(d.value for d in dispatchables)
|
|
14
|
+
|
|
15
|
+
def __ua_function__(self, func, args, kwargs):
|
|
16
|
+
return self.my_types[0]()
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class TypeA:
|
|
20
|
+
@classmethod
|
|
21
|
+
def __repr__(cls):
|
|
22
|
+
return cls.__name__
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class TypeB(TypeA):
|
|
26
|
+
pass
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class TypeC(TypeA):
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
BackendA = _TypedBackend(TypeA)
|
|
34
|
+
BackendB = _TypedBackend(TypeB)
|
|
35
|
+
BackendC = _TypedBackend(TypeC)
|
|
36
|
+
BackendAB = _TypedBackend(TypeA, TypeB)
|
|
37
|
+
BackendBC = _TypedBackend(TypeB, TypeC)
|
|
38
|
+
|
|
39
|
+
creation_multimethod = ua.generate_multimethod(
|
|
40
|
+
lambda: (), lambda a, kw, d: (a, kw), "ua_examples"
|
|
41
|
+
)
|
|
42
|
+
call_multimethod = ua.generate_multimethod(
|
|
43
|
+
lambda *a: tuple(ua.Dispatchable(x, "mark") for x in a),
|
|
44
|
+
lambda a, kw, d: (a, kw),
|
|
45
|
+
"ua_examples",
|
|
46
|
+
)
|