Skip to content

Commit

Permalink
bpo-35461: Document C API functions which suppress exceptions. (GH-11119
Browse files Browse the repository at this point in the history
)
  • Loading branch information
serhiy-storchaka committed Dec 18, 2018
1 parent 62a68b7 commit 3fcc1e0
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Doc/c-api/buffer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ Buffer-related functions
Return ``1`` if *obj* supports the buffer interface otherwise ``0``. When ``1`` is
returned, it doesn't guarantee that :c:func:`PyObject_GetBuffer` will
succeed.
succeed. This function always succeeds.
.. c:function:: int PyObject_GetBuffer(PyObject *exporter, Py_buffer *view, int flags)
Expand Down Expand Up @@ -470,7 +470,7 @@ Buffer-related functions
Return ``1`` if the memory defined by the *view* is C-style (*order* is
``'C'``) or Fortran-style (*order* is ``'F'``) :term:`contiguous` or either one
(*order* is ``'A'``). Return ``0`` otherwise.
(*order* is ``'A'``). Return ``0`` otherwise. This function always succeeds.
.. c:function:: int PyBuffer_ToContiguous(void *buf, Py_buffer *src, Py_ssize_t len, char order)
Expand Down
2 changes: 1 addition & 1 deletion Doc/c-api/codec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Codec registry and support functions
.. c:function:: int PyCodec_KnownEncoding(const char *encoding)
Return ``1`` or ``0`` depending on whether there is a registered codec for
the given *encoding*.
the given *encoding*. This function always succeeds.
.. c:function:: PyObject* PyCodec_Encode(PyObject *object, const char *encoding, const char *errors)
Expand Down
9 changes: 9 additions & 0 deletions Doc/c-api/dict.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ Dictionary Objects
Return the object from dictionary *p* which has a key *key*. Return *NULL*
if the key *key* is not present, but *without* setting an exception.
Note that exceptions which occur while calling :meth:`__hash__` and
:meth:`__eq__` methods will get suppressed.
To get error reporting use :c:func:`PyDict_GetItemWithError()` instead.
.. c:function:: PyObject* PyDict_GetItemWithError(PyObject *p, PyObject *key)
Expand All @@ -109,6 +113,11 @@ Dictionary Objects
This is the same as :c:func:`PyDict_GetItem`, but *key* is specified as a
:c:type:`const char\*`, rather than a :c:type:`PyObject\*`.
Note that exceptions which occur while calling :meth:`__hash__` and
:meth:`__eq__` methods and creating a temporary string object
will get suppressed.
To get error reporting use :c:func:`PyDict_GetItemWithError()` instead.
.. c:function:: PyObject* PyDict_SetDefault(PyObject *p, PyObject *key, PyObject *default)
Expand Down
8 changes: 8 additions & 0 deletions Doc/c-api/mapping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,21 @@ See also :c:func:`PyObject_GetItem`, :c:func:`PyObject_SetItem` and
This is equivalent to the Python expression ``key in o``.
This function always succeeds.
Note that exceptions which occur while calling the :meth:`__getitem__`
method will get suppressed.
To get error reporting use :c:func:`PyObject_GetItem()` instead.
.. c:function:: int PyMapping_HasKeyString(PyObject *o, const char *key)
Return ``1`` if the mapping object has the key *key* and ``0`` otherwise.
This is equivalent to the Python expression ``key in o``.
This function always succeeds.
Note that exceptions which occur while calling the :meth:`__getitem__`
method and creating a temporary string object will get suppressed.
To get error reporting use :c:func:`PyMapping_GetItemString()` instead.
.. c:function:: PyObject* PyMapping_Keys(PyObject *o)
Expand Down
1 change: 1 addition & 0 deletions Doc/c-api/number.rst
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,4 @@ Number Protocol
Returns ``1`` if *o* is an index integer (has the nb_index slot of the
tp_as_number structure filled in), and ``0`` otherwise.
This function always succeeds.
6 changes: 5 additions & 1 deletion Doc/c-api/objbuffer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ an object, and :c:func:`PyBuffer_Release` when the buffer view can be released.
.. c:function:: int PyObject_CheckReadBuffer(PyObject *o)
Returns ``1`` if *o* supports the single-segment readable buffer interface.
Otherwise returns ``0``.
Otherwise returns ``0``. This function always succeeds.
Note that this function tries to get and release a buffer, and exceptions
which occur while calling correspoding functions will get suppressed.
To get error reporting use :c:func:`PyObject_GetBuffer()` instead.
.. c:function:: int PyObject_AsWriteBuffer(PyObject *obj, void **buffer, Py_ssize_t *buffer_len)
Expand Down
9 changes: 9 additions & 0 deletions Doc/c-api/object.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,22 @@ Object Protocol
is equivalent to the Python expression ``hasattr(o, attr_name)``. This function
always succeeds.
Note that exceptions which occur while calling :meth:`__getattr__` and
:meth:`__getattribute__` methods will get suppressed.
To get error reporting use :c:func:`PyObject_GetAttr()` instead.
.. c:function:: int PyObject_HasAttrString(PyObject *o, const char *attr_name)
Returns ``1`` if *o* has the attribute *attr_name*, and ``0`` otherwise. This
is equivalent to the Python expression ``hasattr(o, attr_name)``. This function
always succeeds.
Note that exceptions which occur while calling :meth:`__getattr__` and
:meth:`__getattribute__` methods and creating a temporary string object
will get suppressed.
To get error reporting use :c:func:`PyObject_GetAttrString()` instead.
.. c:function:: PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name)
Expand Down

0 comments on commit 3fcc1e0

Please sign in to comment.