From 26b801a435f2b0d813a37910047062f0f7dadc89 Mon Sep 17 00:00:00 2001 From: crusaderky Date: Thu, 3 Apr 2025 09:39:24 +0100 Subject: [PATCH 1/4] `__setitem__` type promotion rules for array values --- src/array_api_stubs/_draft/array_object.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/array_api_stubs/_draft/array_object.py b/src/array_api_stubs/_draft/array_object.py index 08d5c0b6e..102bb3282 100644 --- a/src/array_api_stubs/_draft/array_object.py +++ b/src/array_api_stubs/_draft/array_object.py @@ -1134,8 +1134,10 @@ def __setitem__( Indexing semantics when ``key`` is an integer array or a tuple of integers and integer arrays is currently unspecified and thus implementation-defined. This will be revisited in a future revision of this standard. - Setting array values must not affect the data type of ``self``. - - When ``value`` is a Python scalar (i.e., ``int``, ``float``, ``complex``, ``bool``), behavior must follow specification guidance on mixing arrays with Python scalars (see :ref:`type-promotion`). - - When ``value`` is an ``array`` of a different data type than ``self``, how values are cast to the data type of ``self`` is implementation defined. + - ``value`` must be promoted to ``self.dtype`` according to :ref:`type-promotion`; if this is not possible, behavior is undefined. + + .. versionchanged:: 2025.12 + Specified :ref:`type-promotion` when ``value`` is an array. """ def __sub__(self: array, other: Union[int, float, complex, array], /) -> array: From 1e0dc9bb9b54c7febe398cdad99b0ee6328510ec Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 22 Jun 2025 23:29:53 -0700 Subject: [PATCH 2/4] docs: update copy for consistency --- src/array_api_stubs/_draft/array_object.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array_api_stubs/_draft/array_object.py b/src/array_api_stubs/_draft/array_object.py index 102bb3282..8d88ecfe1 100644 --- a/src/array_api_stubs/_draft/array_object.py +++ b/src/array_api_stubs/_draft/array_object.py @@ -1134,7 +1134,7 @@ def __setitem__( Indexing semantics when ``key`` is an integer array or a tuple of integers and integer arrays is currently unspecified and thus implementation-defined. This will be revisited in a future revision of this standard. - Setting array values must not affect the data type of ``self``. - - ``value`` must be promoted to ``self.dtype`` according to :ref:`type-promotion`; if this is not possible, behavior is undefined. + - ``value`` must be promoted to the data type of ``self`` according to :ref:`type-promotion`. If this is not possible, behavior is unspecified and thus implementation-defined. .. versionchanged:: 2025.12 Specified :ref:`type-promotion` when ``value`` is an array. From 39f5338e3eafe71c29d7d643f94ea312f4935046 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 22 Jun 2025 23:30:53 -0700 Subject: [PATCH 3/4] docs: update copy --- src/array_api_stubs/_draft/array_object.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array_api_stubs/_draft/array_object.py b/src/array_api_stubs/_draft/array_object.py index 8d88ecfe1..621b06d98 100644 --- a/src/array_api_stubs/_draft/array_object.py +++ b/src/array_api_stubs/_draft/array_object.py @@ -1134,7 +1134,7 @@ def __setitem__( Indexing semantics when ``key`` is an integer array or a tuple of integers and integer arrays is currently unspecified and thus implementation-defined. This will be revisited in a future revision of this standard. - Setting array values must not affect the data type of ``self``. - - ``value`` must be promoted to the data type of ``self`` according to :ref:`type-promotion`. If this is not possible, behavior is unspecified and thus implementation-defined. + - ``value`` must be promoted to the data type of ``self`` according to :ref:`type-promotion`. If this is not supported according to :ref:`type-promotion`, behavior is unspecified and thus implementation-defined. .. versionchanged:: 2025.12 Specified :ref:`type-promotion` when ``value`` is an array. From 1386d40e60d607c4bb46b488cc4b16ae3bc15421 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 22 Jun 2025 23:31:22 -0700 Subject: [PATCH 4/4] style: remove extra space --- src/array_api_stubs/_draft/array_object.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array_api_stubs/_draft/array_object.py b/src/array_api_stubs/_draft/array_object.py index 621b06d98..0e865b324 100644 --- a/src/array_api_stubs/_draft/array_object.py +++ b/src/array_api_stubs/_draft/array_object.py @@ -1134,7 +1134,7 @@ def __setitem__( Indexing semantics when ``key`` is an integer array or a tuple of integers and integer arrays is currently unspecified and thus implementation-defined. This will be revisited in a future revision of this standard. - Setting array values must not affect the data type of ``self``. - - ``value`` must be promoted to the data type of ``self`` according to :ref:`type-promotion`. If this is not supported according to :ref:`type-promotion`, behavior is unspecified and thus implementation-defined. + - ``value`` must be promoted to the data type of ``self`` according to :ref:`type-promotion`. If this is not supported according to :ref:`type-promotion`, behavior is unspecified and thus implementation-defined. .. versionchanged:: 2025.12 Specified :ref:`type-promotion` when ``value`` is an array.