Skip to content

Commit

Permalink
Rewrite documentation according to review in python#106522.
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka committed Jul 11, 2023
1 parent a9f41bd commit d6a9204
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
24 changes: 14 additions & 10 deletions Doc/c-api/mapping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,30 @@ See also :c:func:`PyObject_GetItem`, :c:func:`PyObject_SetItem` and
.. c:function:: int PyMapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **result)
Variant of :c:func:`PyObject_GetItem` which doesn't raise :exc:`KeyError`.
Variant of :c:func:`PyObject_GetItem` which doesn't raise
:exc:`KeyError` if the key is not found.
Return ``1`` and set ``*result != NULL`` if the key is found.
Return ``0`` and set ``*result == NULL`` if the key is not found;
If the key is found, return ``1`` and set *\*result* to a new
:term:`strong reference` to the corresponding value.
If the key is not found, return ``0`` and set *\*result* to ``NULL``;
the :exc:`KeyError` is silenced.
Return ``-1`` and set ``*result == NULL`` if an error other than
:exc:`KeyError` is raised.
If an error other than :exc:`KeyError` is raised, return ``-1`` and
set *\*result* to ``NULL``.
.. versionadded:: 3.13
.. c:function:: int PyMapping_GetOptionalItemString(PyObject *obj, const char *key, PyObject **result)
Variant of :c:func:`PyMapping_GetItemString` which doesn't raise :exc:`KeyError`.
Variant of :c:func:`PyMapping_GetItemString` which doesn't raise
:exc:`KeyError` if the key is not found.
Return ``1`` and set ``*result != NULL`` if the key is found.
Return ``0`` and set ``*result == NULL`` if the key is not found;
If the key is found, return ``1`` and set *\*result* to a new
:term:`strong reference` to the corresponding value.
If the key is not found, return ``0`` and set *\*result* to ``NULL``;
the :exc:`KeyError` is silenced.
Return ``-1`` and set ``*result == NULL`` if an error other than
:exc:`KeyError` is raised.
If an error other than :exc:`KeyError` is raised, return ``-1`` and
set *\*result* to ``NULL``.
.. versionadded:: 3.13
Expand Down
2 changes: 1 addition & 1 deletion Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ New Features
* Add :c:func:`PyMapping_GetOptionalItem` and
:c:func:`PyMapping_GetOptionalItemString`: variants of
:c:func:`PyObject_GetAttr` and :c:func:`PyMapping_GetItemString` which don't
raise :exc:`KeyError`.
raise :exc:`KeyError` if the key is not found.
These variants are more convenient and faster if the missing key should not
be treated as a failure.
(Contributed by Serhiy Storchaka in :gh:`106307`.)
Expand Down
11 changes: 6 additions & 5 deletions Include/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -811,13 +811,14 @@ PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o,
const char *key);

/* Variants of PyObject_GetItem() and PyMapping_GetItemString() which don't
raise KeyError.
raise KeyError if the key is not found.
Return 1 and set *result != NULL if the key is found.
Return 0 and set *result == NULL if the key is not found;
If the key is found, return 1 and set *result to a new strong
reference to the corresponding value.
If the key is not found, return 0 and set *result to NULL;
the KeyError is silenced.
Return -1 and set *result == NULL if an error other than KeyError
is raised.
If an error other than KeyError is raised, return -1 and
set *result to NULL.
*/
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000
PyAPI_FUNC(int) PyMapping_GetOptionalItem(PyObject *, PyObject *, PyObject **);
Expand Down

0 comments on commit d6a9204

Please sign in to comment.