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

gh-106033: [docs] Improve C API GetItem & HasAttr notes. #106047

Merged
merged 15 commits into from
Jun 24, 2023
19 changes: 12 additions & 7 deletions Doc/c-api/dict.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ 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.
.. note::
gpshead marked this conversation as resolved.
Show resolved Hide resolved

Exceptions that occur while this calls :meth:`~object.__hash__` and
:meth:`~object.__eq__` methods are silently ignored.
Prefer the :c:func:`PyDict_GetItemWithError` function instead.

.. versionchanged:: 3.10
Calling this API without :term:`GIL` held had been allowed for historical
Expand All @@ -120,10 +122,13 @@ Dictionary Objects
This is the same as :c:func:`PyDict_GetItem`, but *key* is specified as a
:c:expr:`const char*`, rather than a :c:expr:`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.
.. note::
gpshead marked this conversation as resolved.
Show resolved Hide resolved

Exceptions that occur while this calls :meth:`~object.__hash__` and
:meth:`~object.__eq__` methods or while creating the temporary :class:`str`
object are silently ignored.
Prefer using the :c:func:`PyDict_GetItemWithError` function with your own
:c:func:`PyUnicode_FromString` *key* instead.


.. c:function:: PyObject* PyDict_SetDefault(PyObject *p, PyObject *key, PyObject *defaultobj)
Expand Down
18 changes: 11 additions & 7 deletions Doc/c-api/object.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ 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.
.. note::
gpshead marked this conversation as resolved.
Show resolved Hide resolved

Exceptions that occur when this calls :meth:`~object.__getattr__` and
:meth:`~object.__getattribute__` methods are silently ignored.
For proper error handling, use :c:func:`PyObject_GetAttr` instead.


.. c:function:: int PyObject_HasAttrString(PyObject *o, const char *attr_name)
Expand All @@ -44,10 +46,12 @@ 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 and creating a temporary string object
will get suppressed.
To get error reporting use :c:func:`PyObject_GetAttrString()` instead.
.. note::
gpshead marked this conversation as resolved.
Show resolved Hide resolved

Exceptions that occur when this calls :meth:`~object.__getattr__` and
:meth:`~object.__getattribute__` methods or while creating the temporary :class:`str`
object are silently ignored.
For proper error handling, use :c:func:`PyObject_GetAttrString` instead.


.. c:function:: PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name)
Expand Down