From bd30caeefa4b6dc475c5f5b65afe789367ee14c2 Mon Sep 17 00:00:00 2001 From: scoder Date: Thu, 11 May 2023 08:37:16 +0200 Subject: [PATCH 1/2] Make behavioural difference to Python set methods clear in C-API docs See https://github.com/capi-workgroup/problems/issues/6 --- Doc/c-api/set.rst | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Doc/c-api/set.rst b/Doc/c-api/set.rst index d642a5f1902e2e..b7967cbeb33600 100644 --- a/Doc/c-api/set.rst +++ b/Doc/c-api/set.rst @@ -121,12 +121,15 @@ or :class:`frozenset` or instances of their subtypes. .. c:function:: int PySet_Contains(PyObject *anyset, PyObject *key) - Return ``1`` if found, ``0`` if not found, and ``-1`` if an error is encountered. Unlike - the Python :meth:`__contains__` method, this function does not automatically - convert unhashable sets into temporary frozensets. Raise a :exc:`TypeError` if - the *key* is unhashable. Raise :exc:`PyExc_SystemError` if *anyset* is not a + Return ``1`` if found, ``0`` if not found, and ``-1`` if an error is encountered. + Raise a :exc:`TypeError` if the *key* is unhashable. + Raise :exc:`PyExc_SystemError` if *anyset* is not a :class:`set`, :class:`frozenset`, or an instance of a subtype. + .. note:: + Unlike the Python :meth:`__contains__` method, this function does not + automatically convert unhashable sets into temporary frozensets. + .. c:function:: int PySet_Add(PyObject *set, PyObject *key) @@ -146,11 +149,13 @@ subtypes but not for instances of :class:`frozenset` or its subtypes. .. c:function:: int PySet_Discard(PyObject *set, PyObject *key) Return ``1`` if found and removed, ``0`` if not found (no action taken), and ``-1`` if an - error is encountered. Does not raise :exc:`KeyError` for missing keys. Raise a - :exc:`TypeError` if the *key* is unhashable. Unlike the Python :meth:`~set.discard` - method, this function does not automatically convert unhashable sets into - temporary frozensets. Raise :exc:`PyExc_SystemError` if *set* is not an - instance of :class:`set` or its subtype. + error is encountered. Does not raise :exc:`KeyError` for missing keys. + Raise a :exc:`TypeError` if the *key* is unhashable. + Raise :exc:`PyExc_SystemError` if *set* is not an instance of :class:`set` or its subtype. + + .. note:: + Unlike the Python :meth:`~set.discard` method, this function does not + automatically convert unhashable sets into temporary frozensets. .. c:function:: PyObject* PySet_Pop(PyObject *set) From e6ca4cc6f68cb5e555eca12ea932be0356c3283a Mon Sep 17 00:00:00 2001 From: scoder Date: Thu, 11 May 2023 08:45:25 +0200 Subject: [PATCH 2/2] Remove trailing whitespace --- Doc/c-api/set.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/c-api/set.rst b/Doc/c-api/set.rst index b7967cbeb33600..b119b9526be05a 100644 --- a/Doc/c-api/set.rst +++ b/Doc/c-api/set.rst @@ -128,7 +128,7 @@ or :class:`frozenset` or instances of their subtypes. .. note:: Unlike the Python :meth:`__contains__` method, this function does not - automatically convert unhashable sets into temporary frozensets. + automatically convert unhashable sets into temporary frozensets. .. c:function:: int PySet_Add(PyObject *set, PyObject *key)