From 50bad52b273d124beb0e461814f8459f69dd12f7 Mon Sep 17 00:00:00 2001 From: nstarman Date: Tue, 12 Sep 2023 00:43:04 -0400 Subject: [PATCH 1/3] Add protocol for namespace Signed-off-by: nstarman --- src/array_api_stubs/_draft/_namespace.py | 8 ++++++++ src/array_api_stubs/_draft/array_object.py | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/array_api_stubs/_draft/_namespace.py diff --git a/src/array_api_stubs/_draft/_namespace.py b/src/array_api_stubs/_draft/_namespace.py new file mode 100644 index 000000000..eeb2f66b7 --- /dev/null +++ b/src/array_api_stubs/_draft/_namespace.py @@ -0,0 +1,8 @@ +__all__ = ["ArrayAPINamespace"] + +from typing import Protocol + + +class ArrayAPINamespace(Protocol): + """Protocol for the array API namespace itself.""" + diff --git a/src/array_api_stubs/_draft/array_object.py b/src/array_api_stubs/_draft/array_object.py index cf6adcf3c..cba6d2f98 100644 --- a/src/array_api_stubs/_draft/array_object.py +++ b/src/array_api_stubs/_draft/array_object.py @@ -1,5 +1,7 @@ from __future__ import annotations +from typing import TYPE_CHECKING + from ._types import ( array, dtype as Dtype, @@ -13,6 +15,9 @@ ellipsis, ) +if TYPE_CHECKING: + from ._namespace import ArrayAPINamespace + class _array: def __init__(self: array) -> None: @@ -195,7 +200,7 @@ def __and__(self: array, other: Union[int, bool, array], /) -> array: def __array_namespace__( self: array, /, *, api_version: Optional[str] = None - ) -> Any: + ) -> ArrayAPINamespace: """ Returns an object that has all the array API functions on it. From 463dba13dc7c55c3cc241367142742086eb37fc3 Mon Sep 17 00:00:00 2001 From: nstarman Date: Tue, 12 Sep 2023 00:43:20 -0400 Subject: [PATCH 2/3] convert arange to a protocol Signed-off-by: nstarman --- src/array_api_stubs/_draft/_namespace.py | 3 +++ .../_draft/creation_functions.py | 23 +++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/array_api_stubs/_draft/_namespace.py b/src/array_api_stubs/_draft/_namespace.py index eeb2f66b7..d68780b22 100644 --- a/src/array_api_stubs/_draft/_namespace.py +++ b/src/array_api_stubs/_draft/_namespace.py @@ -2,7 +2,10 @@ from typing import Protocol +from .creation_functions import arange as ArangeCallable + class ArrayAPINamespace(Protocol): """Protocol for the array API namespace itself.""" + arange: ArangeCallable diff --git a/src/array_api_stubs/_draft/creation_functions.py b/src/array_api_stubs/_draft/creation_functions.py index 42d6f9420..ee629142f 100644 --- a/src/array_api_stubs/_draft/creation_functions.py +++ b/src/array_api_stubs/_draft/creation_functions.py @@ -1,3 +1,4 @@ +from typing import Protocol from ._types import ( List, NestedSequence, @@ -11,15 +12,7 @@ ) -def arange( - start: Union[int, float], - /, - stop: Optional[Union[int, float]] = None, - step: Union[int, float] = 1, - *, - dtype: Optional[dtype] = None, - device: Optional[device] = None, -) -> array: +class arange(Protocol): """ Returns evenly spaced values within the half-open interval ``[start, stop)`` as a one-dimensional array. @@ -46,6 +39,18 @@ def arange( a one-dimensional array containing evenly spaced values. The length of the output array must be ``ceil((stop-start)/step)`` if ``stop - start`` and ``step`` have the same sign, and length ``0`` otherwise. """ + def __call__( + self, + start: Union[int, float], + /, + stop: Optional[Union[int, float]] = None, + step: Union[int, float] = 1, + *, + dtype: Optional[dtype] = None, + device: Optional[device] = None, + ) -> array: + ... + def asarray( obj: Union[ From 10b9e36156e45a50c98b898529701073a637722f Mon Sep 17 00:00:00 2001 From: nstarman Date: Tue, 12 Sep 2023 00:49:12 -0400 Subject: [PATCH 3/3] Add nitpick ignore Signed-off-by: nstarman --- src/_array_api_conf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/_array_api_conf.py b/src/_array_api_conf.py index e183082ec..539b55465 100644 --- a/src/_array_api_conf.py +++ b/src/_array_api_conf.py @@ -57,6 +57,7 @@ ('py:obj', "typing.Union[int, float, typing.Literal[inf, - inf]]"), ('py:class', 'enum.Enum'), ('py:class', 'ellipsis'), + ("py:class", "ArrayAPINamespace"), ] nitpick_ignore_regex = [ ('py:class', '.*array'), pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy