summaryrefslogtreecommitdiffstats
path: root/Doc/c-api
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-09-17 11:23:31 (GMT)
committerGitHub <noreply@github.com>2023-09-17 11:23:31 (GMT)
commitadd16f1a5e4013f97d33cc677dc008e8199f5b11 (patch)
tree2c187adbae2766f942e35780950a526dfe84ff48 /Doc/c-api
parente57ecf6bbc59f999d27b125ea51b042c24a07bd9 (diff)
downloadcpython-add16f1a5e4013f97d33cc677dc008e8199f5b11.zip
cpython-add16f1a5e4013f97d33cc677dc008e8199f5b11.tar.gz
cpython-add16f1a5e4013f97d33cc677dc008e8199f5b11.tar.bz2
gh-108511: Add C API functions which do not silently ignore errors (GH-109025)
Add the following functions: * PyObject_HasAttrWithError() * PyObject_HasAttrStringWithError() * PyMapping_HasKeyWithError() * PyMapping_HasKeyStringWithError()
Diffstat (limited to 'Doc/c-api')
-rw-r--r--Doc/c-api/mapping.rst25
-rw-r--r--Doc/c-api/object.rst25
2 files changed, 44 insertions, 6 deletions
diff --git a/Doc/c-api/mapping.rst b/Doc/c-api/mapping.rst
index 5b909ef..1f55c0a 100644
--- a/Doc/c-api/mapping.rst
+++ b/Doc/c-api/mapping.rst
@@ -76,6 +76,24 @@ See also :c:func:`PyObject_GetItem`, :c:func:`PyObject_SetItem` and
rather than a :c:expr:`PyObject*`.
+.. c:function:: int PyMapping_HasKeyWithError(PyObject *o, PyObject *key)
+
+ Return ``1`` if the mapping object has the key *key* and ``0`` otherwise.
+ This is equivalent to the Python expression ``key in o``.
+ On failure, return ``-1``.
+
+ .. versionadded:: 3.13
+
+
+.. c:function:: int PyMapping_HasKeyStringWithError(PyObject *o, const char *key)
+
+ This is the same as :c:func:`PyMapping_HasKeyWithError`, but *key* is
+ specified as a :c:expr:`const char*` UTF-8 encoded bytes string,
+ rather than a :c:expr:`PyObject*`.
+
+ .. versionadded:: 3.13
+
+
.. c:function:: int PyMapping_HasKey(PyObject *o, PyObject *key)
Return ``1`` if the mapping object has the key *key* and ``0`` otherwise.
@@ -86,8 +104,8 @@ See also :c:func:`PyObject_GetItem`, :c:func:`PyObject_SetItem` and
Exceptions which occur when this calls :meth:`~object.__getitem__`
method are silently ignored.
- For proper error handling, use :c:func:`PyMapping_GetOptionalItem` or
- :c:func:`PyObject_GetItem()` instead.
+ For proper error handling, use :c:func:`PyMapping_HasKeyWithError`,
+ :c:func:`PyMapping_GetOptionalItem` or :c:func:`PyObject_GetItem()` instead.
.. c:function:: int PyMapping_HasKeyString(PyObject *o, const char *key)
@@ -101,7 +119,8 @@ See also :c:func:`PyObject_GetItem`, :c:func:`PyObject_SetItem` and
Exceptions that occur when this calls :meth:`~object.__getitem__`
method or while creating the temporary :class:`str`
object are silently ignored.
- For proper error handling, use :c:func:`PyMapping_GetOptionalItemString` or
+ For proper error handling, use :c:func:`PyMapping_HasKeyStringWithError`,
+ :c:func:`PyMapping_GetOptionalItemString` or
:c:func:`PyMapping_GetItemString` instead.
diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst
index 2572c08..bf55b57 100644
--- a/Doc/c-api/object.rst
+++ b/Doc/c-api/object.rst
@@ -27,6 +27,24 @@ Object Protocol
instead of the :func:`repr`.
+.. c:function:: int PyObject_HasAttrWithError(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)``.
+ On failure, return ``-1``.
+
+ .. versionadded:: 3.13
+
+
+.. c:function:: int PyObject_HasAttrStringWithError(PyObject *o, const char *attr_name)
+
+ This is the same as :c:func:`PyObject_HasAttrWithError`, but *attr_name* is
+ specified as a :c:expr:`const char*` UTF-8 encoded bytes string,
+ rather than a :c:expr:`PyObject*`.
+
+ .. versionadded:: 3.13
+
+
.. c:function:: int PyObject_HasAttr(PyObject *o, PyObject *attr_name)
Returns ``1`` if *o* has the attribute *attr_name*, and ``0`` otherwise. This
@@ -37,8 +55,8 @@ Object Protocol
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_GetOptionalAttr` or
- :c:func:`PyObject_GetAttr` instead.
+ For proper error handling, use :c:func:`PyObject_HasAttrWithError`,
+ :c:func:`PyObject_GetOptionalAttr` or :c:func:`PyObject_GetAttr` instead.
.. c:function:: int PyObject_HasAttrString(PyObject *o, const char *attr_name)
@@ -52,7 +70,8 @@ Object Protocol
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_GetOptionalAttrString`
+ For proper error handling, use :c:func:`PyObject_HasAttrStringWithError`,
+ :c:func:`PyObject_GetOptionalAttrString`
or :c:func:`PyObject_GetAttrString` instead.