Skip to content

Commit 267a41c

Browse files
authored
Allow lazy implementations to raise from intrinsically eager functions (#652)
1 parent ab69aa2 commit 267a41c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/array_api_stubs/_draft/array_object.py

+26
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ def __bool__(self: array, /) -> bool:
241241
242242
For complex floating-point operands, special cases must be handled as if the operation is implemented as the logical AND of ``bool(real(self))`` and ``bool(imag(self))``.
243243
244+
**Lazy implementations**
245+
246+
The Python language requires the return value to be of type ``bool``. Lazy implementations are therefore not able to return any kind of lazy/delayed object here and should raise a ``ValueError`` instead.
247+
244248
.. versionchanged:: 2022.12
245249
Added boolean and complex data type support.
246250
"""
@@ -276,6 +280,10 @@ def __complex__(self: array, /) -> complex:
276280
- If ``self`` is ``-infinity``, the result is ``-infinity + 0j``.
277281
- If ``self`` is a finite number, the result is ``self + 0j``.
278282
283+
**Lazy implementations**
284+
285+
The Python language requires the return value to be of type ``complex``. Lazy implementations are therefore not able to return any kind of lazy/delayed object here and should raise a ``ValueError`` instead.
286+
279287
.. versionadded:: 2022.12
280288
"""
281289

@@ -424,6 +432,10 @@ def __float__(self: array, /) -> float:
424432
- If ``self`` is ``True``, the result is ``1``.
425433
- If ``self`` is ``False``, the result is ``0``.
426434
435+
**Lazy implementations**
436+
437+
The Python language requires the return value to be of type ``float``. Lazy implementations are therefore not able to return any kind of lazy/delayed object here and should raise a ``ValueError`` instead.
438+
427439
.. versionchanged:: 2022.12
428440
Added boolean and complex data type support.
429441
"""
@@ -544,6 +556,13 @@ def __index__(self: array, /) -> int:
544556
-------
545557
out: int
546558
a Python ``int`` object representing the single element of the array instance.
559+
560+
Notes
561+
-----
562+
563+
**Lazy implementations**
564+
565+
The Python language requires the return value to be of type ``int``. Lazy implementations are therefore not able to return any kind of lazy/delayed object here and should raise a ``ValueError`` instead.
547566
"""
548567

549568
def __int__(self: array, /) -> int:
@@ -582,6 +601,13 @@ def __int__(self: array, /) -> int:
582601
- If ``self`` is either ``+infinity`` or ``-infinity``, raise ``OverflowError``.
583602
- If ``self`` is ``NaN``, raise ``ValueError``.
584603
604+
Notes
605+
-----
606+
607+
**Lazy implementations**
608+
609+
The Python language requires the return value to be of type ``int``. Lazy implementations are therefore not able to return any kind of lazy/delayed object here and should raise a ``ValueError`` instead.
610+
585611
.. versionchanged:: 2022.12
586612
Added boolean and complex data type support.
587613
"""

0 commit comments

Comments
 (0)