Skip to content

Commit

Permalink
Allow lazy implementations to raise from intrinsically eager functions (
Browse files Browse the repository at this point in the history
  • Loading branch information
cbourjau authored Nov 16, 2023
1 parent ab69aa2 commit 267a41c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/array_api_stubs/_draft/array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ def __bool__(self: array, /) -> bool:
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))``.
**Lazy implementations**
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.
.. versionchanged:: 2022.12
Added boolean and complex data type support.
"""
Expand Down Expand Up @@ -276,6 +280,10 @@ def __complex__(self: array, /) -> complex:
- If ``self`` is ``-infinity``, the result is ``-infinity + 0j``.
- If ``self`` is a finite number, the result is ``self + 0j``.
**Lazy implementations**
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.
.. versionadded:: 2022.12
"""

Expand Down Expand Up @@ -424,6 +432,10 @@ def __float__(self: array, /) -> float:
- If ``self`` is ``True``, the result is ``1``.
- If ``self`` is ``False``, the result is ``0``.
**Lazy implementations**
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.
.. versionchanged:: 2022.12
Added boolean and complex data type support.
"""
Expand Down Expand Up @@ -544,6 +556,13 @@ def __index__(self: array, /) -> int:
-------
out: int
a Python ``int`` object representing the single element of the array instance.
Notes
-----
**Lazy implementations**
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.
"""

def __int__(self: array, /) -> int:
Expand Down Expand Up @@ -582,6 +601,13 @@ def __int__(self: array, /) -> int:
- If ``self`` is either ``+infinity`` or ``-infinity``, raise ``OverflowError``.
- If ``self`` is ``NaN``, raise ``ValueError``.
Notes
-----
**Lazy implementations**
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.
.. versionchanged:: 2022.12
Added boolean and complex data type support.
"""
Expand Down

0 comments on commit 267a41c

Please sign in to comment.