From 74dcea65b64eb7def77de3fbb6d8f3a57508922c Mon Sep 17 00:00:00 2001 From: Hugh Perkins Date: Wed, 11 Mar 2026 20:04:53 -0700 Subject: [PATCH 1/2] [Fix] Fix NDArray single-arg subscript crash NdarrayType.__class_getitem__ crashed when called with a single arg (e.g. NdarrayType[dtype]) because it tried to unpack a non-tuple. Wrap single args in a tuple before passing to __init__. --- python/quadrants/types/ndarray_type.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/python/quadrants/types/ndarray_type.py b/python/quadrants/types/ndarray_type.py index 994fa70b5..9ed077b67 100644 --- a/python/quadrants/types/ndarray_type.py +++ b/python/quadrants/types/ndarray_type.py @@ -94,8 +94,10 @@ def __init__( self.boundary = int(to_boundary_enum(boundary)) @classmethod - def __class_getitem__(cls, args, **kwargs): - return cls(*args, **kwargs) + def __class_getitem__(cls, args): + if not isinstance(args, tuple): + args = (args,) + return cls(*args) def check_matched(self, ndarray_type: NdarrayTypeMetadata, arg_name: str): # FIXME(Haidong) Cannot use Vector/MatrixType due to circular import From 050f3a73cf795370e047e7ebf2a0a4b3026c49ca Mon Sep 17 00:00:00 2001 From: Hugh Perkins Date: Wed, 11 Mar 2026 21:33:57 -0700 Subject: [PATCH 2/2] [Test] Add test for single-arg NDArray subscript syntax Test that NDArray[dtype] (without ndim) works and produces an NdarrayType with the correct dtype and ndim=None. --- tests/python/test_ndarray_typing.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/python/test_ndarray_typing.py b/tests/python/test_ndarray_typing.py index 0ce6b4b7d..531c786ce 100644 --- a/tests/python/test_ndarray_typing.py +++ b/tests/python/test_ndarray_typing.py @@ -16,3 +16,9 @@ def test_ndarray_typing_square_brackets(): b[1, 1] = 5 some_kernel(a, b) assert a[1, 1] == 5 + 2 + + +def test_ndarray_typing_single_arg(): + t = qd.types.NDArray[qd.i32] + assert t.dtype == qd.i32 + assert t.ndim is None