From f0059bdb7b921427e9d43306f6f1d3564adf2499 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Sat, 11 Mar 2023 12:38:44 +0300 Subject: [PATCH 1/3] gh-102595: Document `PyObject_Format` c-api function --- Doc/c-api/object.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst index 84c72e7e108b64..90161818e74f08 100644 --- a/Doc/c-api/object.rst +++ b/Doc/c-api/object.rst @@ -179,6 +179,13 @@ Object Protocol If *o1* and *o2* are the same object, :c:func:`PyObject_RichCompareBool` will always return ``1`` for :const:`Py_EQ` and ``0`` for :const:`Py_NE`. +.. c:function:: PyObject* PyObject_Format(PyObject *obj, PyObject *format_spec) + + Takes an arbitrary *obj* and returns the result of calling + ``obj.__format__(format_spec)``. + + *format_spec* might be ``NULL`` when ``format(obj)`` is used. + .. c:function:: PyObject* PyObject_Repr(PyObject *o) .. index:: builtin: repr From 5ca5977aee2a3ed7a1905cd911ec689323a9ae80 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Sat, 11 Mar 2023 18:27:31 +0300 Subject: [PATCH 2/3] Update Doc/c-api/object.rst Co-authored-by: Jelle Zijlstra --- Doc/c-api/object.rst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst index 90161818e74f08..c356a4bf9a0922 100644 --- a/Doc/c-api/object.rst +++ b/Doc/c-api/object.rst @@ -181,10 +181,13 @@ Object Protocol .. c:function:: PyObject* PyObject_Format(PyObject *obj, PyObject *format_spec) - Takes an arbitrary *obj* and returns the result of calling - ``obj.__format__(format_spec)``. + Format *obj* using *format_spec*. This is equivalent to the Python + expression ``format(obj, format_spec)``. - *format_spec* might be ``NULL`` when ``format(obj)`` is used. + *format_spec* may be ``NULL``. In this case the call is equivalent + to ``format(obj)``. + + Returns the formatted string on success, ``NULL`` on failure. .. c:function:: PyObject* PyObject_Repr(PyObject *o) From fe429a0a2033431bbec02e70fb45fd959a8a55e1 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 11 Mar 2023 07:35:51 -0800 Subject: [PATCH 3/3] Update Doc/c-api/object.rst --- Doc/c-api/object.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst index c356a4bf9a0922..0a12bb9e8c54f0 100644 --- a/Doc/c-api/object.rst +++ b/Doc/c-api/object.rst @@ -186,7 +186,6 @@ Object Protocol *format_spec* may be ``NULL``. In this case the call is equivalent to ``format(obj)``. - Returns the formatted string on success, ``NULL`` on failure. .. c:function:: PyObject* PyObject_Repr(PyObject *o)