From a52e9495f4fe77bf39654ef102ebac99ff994340 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Tue, 11 Nov 2025 11:09:07 -0500 Subject: [PATCH 1/4] Document PyFile_OpenCode() and PyFile_OpenCodeObject(). --- Doc/c-api/file.rst | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Doc/c-api/file.rst b/Doc/c-api/file.rst index e9019a0d500f7e..d67e7334de9ae1 100644 --- a/Doc/c-api/file.rst +++ b/Doc/c-api/file.rst @@ -93,6 +93,30 @@ the :mod:`io` APIs instead. .. versionadded:: 3.8 +.. c:function:: PyObject *PyFile_OpenCodeObject(PyObject *path) + + Open *path* and read the text. *path* must be a Python :class:`str` + object. The behavior of this function may be overridden by + :c:func:`PyFile_SetOpenCodeHook` to allow for some preprocessing of the + text. + + This is analogous to :func:`io.open_code` in Python. + + On success, this function returns a :term:`strong reference` to a Python + file object. On failure, this function returns ``NULL`` with an exception + set. + + .. versionadded:: 3.8 + + +.. c:function:: PyObject *PyFile_OpenCode(const char *path) + + Similar to :c:func:`PyFile_OpenCodeObject`, but *path* is a + :c:expr:`const char*` that is decoded by the + :term:`filesystem encoding and error handler`. + + .. versionadded:: 3.8 + .. c:function:: int PyFile_WriteObject(PyObject *obj, PyObject *p, int flags) @@ -108,3 +132,4 @@ the :mod:`io` APIs instead. Write string *s* to file object *p*. Return ``0`` on success or ``-1`` on failure; the appropriate exception will be set. + From 682cdbf4f34a3a604883e5e4aa3ca553d48f93ed Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Tue, 11 Nov 2025 11:09:56 -0500 Subject: [PATCH 2/4] Remove stray newline change. --- Doc/c-api/file.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/Doc/c-api/file.rst b/Doc/c-api/file.rst index d67e7334de9ae1..bd1d001d5b67e9 100644 --- a/Doc/c-api/file.rst +++ b/Doc/c-api/file.rst @@ -132,4 +132,3 @@ the :mod:`io` APIs instead. Write string *s* to file object *p*. Return ``0`` on success or ``-1`` on failure; the appropriate exception will be set. - From 598c259ee791d00fb9905946a206986309ddde45 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Tue, 11 Nov 2025 12:27:29 -0500 Subject: [PATCH 3/4] Document the string as UTF-8. --- Doc/c-api/file.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Doc/c-api/file.rst b/Doc/c-api/file.rst index bd1d001d5b67e9..d309a8fd33674c 100644 --- a/Doc/c-api/file.rst +++ b/Doc/c-api/file.rst @@ -112,8 +112,7 @@ the :mod:`io` APIs instead. .. c:function:: PyObject *PyFile_OpenCode(const char *path) Similar to :c:func:`PyFile_OpenCodeObject`, but *path* is a - :c:expr:`const char*` that is decoded by the - :term:`filesystem encoding and error handler`. + UTF-8 encoded :c:expr:`const char*`. .. versionadded:: 3.8 From 145d2d26443ea7a7c3308bfa720b947249cebdaf Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Tue, 11 Nov 2025 13:31:04 -0500 Subject: [PATCH 4/4] Update Doc/c-api/file.rst Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- Doc/c-api/file.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/c-api/file.rst b/Doc/c-api/file.rst index d309a8fd33674c..9d01254ddb2a11 100644 --- a/Doc/c-api/file.rst +++ b/Doc/c-api/file.rst @@ -95,7 +95,7 @@ the :mod:`io` APIs instead. .. c:function:: PyObject *PyFile_OpenCodeObject(PyObject *path) - Open *path* and read the text. *path* must be a Python :class:`str` + Open *path* with the mode ``'rb'``. *path* must be a Python :class:`str` object. The behavior of this function may be overridden by :c:func:`PyFile_SetOpenCodeHook` to allow for some preprocessing of the text.