From c1dea84952b9c3f528c064226ca53408aa65795e Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Tue, 26 Dec 2023 07:08:21 -0600 Subject: [PATCH] do something with no errors --- src/ragged/api_2022_12/__init__.py | 6 ++++-- src/ragged/common/__init__.py | 10 ++++++++-- src/ragged/common/_typing.py | 12 ++++++++++-- tests/test_0001_initial_array_object.py | 7 ++++--- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/ragged/api_2022_12/__init__.py b/src/ragged/api_2022_12/__init__.py index 6167020..30f3fbe 100644 --- a/src/ragged/api_2022_12/__init__.py +++ b/src/ragged/api_2022_12/__init__.py @@ -5,5 +5,7 @@ from ..common import array as common_array -class array(common_array): - pass +class array(common_array): # pylint: disable=C0103 + """ + Ragged array class and constructor for data-apis.org/array-api/2022.12. + """ diff --git a/src/ragged/common/__init__.py b/src/ragged/common/__init__.py index 368cc33..3dcfa44 100644 --- a/src/ragged/common/__init__.py +++ b/src/ragged/common/__init__.py @@ -7,7 +7,11 @@ from ._typing import Device, Dtype, NestedSequence, SupportsDLPack -class array: +class array: # pylint: disable=C0103 + """ + Ragged array class and constructor. + """ + def __init__( self, array_like: ( @@ -22,4 +26,6 @@ def __init__( dtype: None | Dtype = None, device: None | Device = None, ): - ... + assert array_like is not None + assert dtype is None + assert device is None diff --git a/src/ragged/common/_typing.py b/src/ragged/common/_typing.py index cdeb565..b383be5 100644 --- a/src/ragged/common/_typing.py +++ b/src/ragged/common/_typing.py @@ -14,6 +14,10 @@ class NestedSequence(Protocol[T_co]): + """ + Python list of list of ... some type. + """ + def __getitem__(self, key: int, /) -> T_co | NestedSequence[T_co]: ... @@ -25,6 +29,10 @@ def __len__(self, /) -> int: class SupportsDLPack(Protocol): + """ + Array type that supports DLPack. + """ + def __dlpack__(self, /, *, stream: None = ...) -> PyCapsule: ... @@ -32,7 +40,7 @@ def __dlpack__(self, /, *, stream: None = ...) -> PyCapsule: Device = Union[Literal["cpu"], Literal["cuda"]] Dtype = np.dtype[ - ( + Union[ np.int8, np.int16, np.int32, @@ -43,5 +51,5 @@ def __dlpack__(self, /, *, stream: None = ...) -> PyCapsule: np.uint64, np.float32, np.float64, - ) + ] ] diff --git a/tests/test_0001_initial_array_object.py b/tests/test_0001_initial_array_object.py index 51997ca..57db5bf 100644 --- a/tests/test_0001_initial_array_object.py +++ b/tests/test_0001_initial_array_object.py @@ -2,8 +2,9 @@ from __future__ import annotations -# import ragged +import ragged -# def test(): -# a = ragged.array([1, 2, 3]) +def test(): + a = ragged.array([1, 2, "hello", 3]) + assert a is not None