Skip to content

Commit d17ebec

Browse files
gh-90241: Clarify documentation for PyUnicode_FSConverter and PyUnicode_FSDecoder
1 parent 621d4ff commit d17ebec

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

Doc/c-api/arg.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ Other objects
307307

308308
.. _o_ampersand:
309309

310-
``O&`` (object) [*converter*, *anything*]
310+
``O&`` (object) [*converter*, *address*]
311311
Convert a Python object to a C variable through a *converter* function. This
312312
takes two arguments: the first is a function, the second is the address of a C
313313
variable (of arbitrary type), converted to :c:expr:`void *`. The *converter*
@@ -327,6 +327,9 @@ Other objects
327327
call, the *object* parameter will be ``NULL``; *address* will have the same value
328328
as in the original call.
329329

330+
Examples of converters: :c:func:`PyUnicode_FSConverter` and
331+
:c:func:`PyUnicode_FSDecoder`.
332+
330333
.. versionchanged:: 3.1
331334
``Py_CLEANUP_SUPPORTED`` was added.
332335

Doc/c-api/unicode.rst

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -786,33 +786,48 @@ Functions encoding to and decoding from the :term:`filesystem encoding and
786786
error handler` (:pep:`383` and :pep:`529`).
787787
788788
To encode file names to :class:`bytes` during argument parsing, the ``"O&"``
789-
converter should be used, passing :c:func:`PyUnicode_FSConverter` as the
789+
converter should be used, passing :c:func:`!PyUnicode_FSConverter` as the
790790
conversion function:
791791
792792
.. c:function:: int PyUnicode_FSConverter(PyObject* obj, void* result)
793793
794-
ParseTuple converter: encode :class:`str` objects -- obtained directly or
794+
:ref:`PyArg_Parse\* converter <arg-parsing>`: encode :class:`str` objects -- obtained directly or
795795
through the :class:`os.PathLike` interface -- to :class:`bytes` using
796796
:c:func:`PyUnicode_EncodeFSDefault`; :class:`bytes` objects are output as-is.
797-
*result* must be a :c:expr:`PyBytesObject*` which must be released when it is
798-
no longer used.
797+
*result* must be an address of a C variable of type :c:expr:`PyObject*`
798+
(or :c:expr:`PyBytesObject*`).
799+
The variable is set to a new :term:`strong reference` to
800+
a :ref:`bytes object <bytesobjects>` which must be released
801+
when it is no longer used.
802+
Embedded null bytes are not allowed in the result.
803+
804+
If *obj* is ``NULL``, the function releases a strong reference
805+
stored in the variable referred by *result*.
799806
800807
.. versionadded:: 3.1
801808
802809
.. versionchanged:: 3.6
803810
Accepts a :term:`path-like object`.
804811
805812
To decode file names to :class:`str` during argument parsing, the ``"O&"``
806-
converter should be used, passing :c:func:`PyUnicode_FSDecoder` as the
813+
converter should be used, passing :c:func:`!PyUnicode_FSDecoder` as the
807814
conversion function:
808815
809816
.. c:function:: int PyUnicode_FSDecoder(PyObject* obj, void* result)
810817
811-
ParseTuple converter: decode :class:`bytes` objects -- obtained either
818+
:ref:`PyArg_Parse\* converter <arg-parsing>`: decode :class:`bytes` objects -- obtained either
812819
directly or indirectly through the :class:`os.PathLike` interface -- to
813820
:class:`str` using :c:func:`PyUnicode_DecodeFSDefaultAndSize`; :class:`str`
814-
objects are output as-is. *result* must be a :c:expr:`PyUnicodeObject*` which
815-
must be released when it is no longer used.
821+
objects are output as-is.
822+
*result* must be an address of a C variable of type :c:expr:`PyObject*`
823+
(or :c:expr:`PyUnicodeObject*`).
824+
The variable is set to a new :term:`strong reference` to
825+
a :ref:`Unicode object <unicodeobjects>` which must be released
826+
when it is no longer used.
827+
Embedded null characters are not allowed in the result.
828+
829+
If *obj* is ``NULL``, the function releases a strong reference
830+
stored in the variable referred by *result*.
816831
817832
.. versionadded:: 3.2
818833

0 commit comments

Comments
 (0)