-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathprotocols.py
More file actions
62 lines (38 loc) · 1.22 KB
/
protocols.py
File metadata and controls
62 lines (38 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from __future__ import annotations
from collections.abc import Callable
from typing import Any, Protocol, runtime_checkable
ARRAY_LIKE_ATTRS = [
"__array__",
"__array_ufunc__",
"dtype",
"shape",
"ndim",
"__getitem__",
]
@runtime_checkable
class ArrayProtocol(Protocol):
"""an object that is sufficiently array-like"""
def __array__(self) -> ArrayProtocol: ...
@property
def dtype(self) -> Any: ...
@property
def ndim(self) -> int: ...
@property
def shape(self) -> tuple[int, ...]: ...
def __getitem__(self, key) -> ArrayProtocol: ...
@runtime_checkable
class CudaArrayProtocol(Protocol):
"""an object that can be converted to a cupy array"""
def __cuda_array_interface__(self) -> CudaArrayProtocol: ...
@runtime_checkable
class FutureProtocol(Protocol):
"""An object that is sufficiently Future-like"""
def cancel(self): ...
def cancelled(self): ...
def running(self): ...
def done(self): ...
def add_done_callback(self, fn: Callable): ...
def result(self, timeout: float | None): ...
def exception(self, timeout: float | None): ...
def set_result(self, array: ArrayProtocol): ...
def set_exception(self, exception): ...