Skip to content

Improve slice C-API docs by mentioning exceptions #121567

@sobolevn

Description

@sobolevn

There are two cases where we can add explicit with exception set part. First one is:

.. c:function:: PyObject* PySlice_New(PyObject *start, PyObject *stop, PyObject *step)
Return a new slice object with the given values. The *start*, *stop*, and
*step* parameters are used as the values of the slice object attributes of
the same names. Any of the values may be ``NULL``, in which case the
``None`` will be used for the corresponding attribute. Return ``NULL`` if
the new object could not be allocated.

Notice this part:

Return NULL if the new object could not be allocated.

And:

.. c:function:: int PySlice_Unpack(PyObject *slice, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step)
Extract the start, stop and step data members from a slice object as
C integers. Silently reduce values larger than ``PY_SSIZE_T_MAX`` to
``PY_SSIZE_T_MAX``, silently boost the start and stop values less than
``PY_SSIZE_T_MIN`` to ``PY_SSIZE_T_MIN``, and silently boost the step
values less than ``-PY_SSIZE_T_MAX`` to ``-PY_SSIZE_T_MAX``.
Return ``-1`` on error, ``0`` on success.
.. versionadded:: 3.6.1

Return ``-1`` on error, ``0`` on success.

Linked PRs

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions