forked from data-apis/array-api-typing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_namespace.py
More file actions
30 lines (23 loc) · 785 Bytes
/
_namespace.py
File metadata and controls
30 lines (23 loc) · 785 Bytes
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
__all__ = ("HasArrayNamespace",)
from types import ModuleType
from typing import Literal, Protocol
from typing_extensions import TypeVar
T_co = TypeVar("T_co", covariant=True, default=ModuleType)
class HasArrayNamespace(Protocol[T_co]):
"""Protocol for classes that have an `__array_namespace__` method.
Example:
>>> import array_api_typing as xpt
>>>
>>> class MyArray:
... def __array_namespace__(self):
... return object()
>>>
>>> x = MyArray()
>>> def has_array_namespace(x: xpt.HasArrayNamespace) -> bool:
... return hasattr(x, "__array_namespace__")
>>> has_array_namespace(x)
True
"""
def __array_namespace__(
self, /, *, api_version: Literal["2021.12"] | None = None
) -> T_co: ...