Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow lazy implementations to raise from intrinsically eager functions #652

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -239,6 +239,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 @@ -274,6 +278,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 @@ -422,6 +430,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 @@ -537,6 +549,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 @@ -575,6 +594,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