Skip to content

Commit

Permalink
pythongh-90241: Clarify documentation for PyUnicode_FSConverter and P…
Browse files Browse the repository at this point in the history
…yUnicode_FSDecoder
  • Loading branch information
serhiy-storchaka committed Jan 3, 2025
1 parent 621d4ff commit d17ebec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
5 changes: 4 additions & 1 deletion Doc/c-api/arg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ Other objects

.. _o_ampersand:

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

Examples of converters: :c:func:`PyUnicode_FSConverter` and
:c:func:`PyUnicode_FSDecoder`.

.. versionchanged:: 3.1
``Py_CLEANUP_SUPPORTED`` was added.

Expand Down
31 changes: 23 additions & 8 deletions Doc/c-api/unicode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -786,33 +786,48 @@ Functions encoding to and decoding from the :term:`filesystem encoding and
error handler` (:pep:`383` and :pep:`529`).
To encode file names to :class:`bytes` during argument parsing, the ``"O&"``
converter should be used, passing :c:func:`PyUnicode_FSConverter` as the
converter should be used, passing :c:func:`!PyUnicode_FSConverter` as the
conversion function:
.. c:function:: int PyUnicode_FSConverter(PyObject* obj, void* result)
ParseTuple converter: encode :class:`str` objects -- obtained directly or
:ref:`PyArg_Parse\* converter <arg-parsing>`: encode :class:`str` objects -- obtained directly or
through the :class:`os.PathLike` interface -- to :class:`bytes` using
:c:func:`PyUnicode_EncodeFSDefault`; :class:`bytes` objects are output as-is.
*result* must be a :c:expr:`PyBytesObject*` which must be released when it is
no longer used.
*result* must be an address of a C variable of type :c:expr:`PyObject*`
(or :c:expr:`PyBytesObject*`).
The variable is set to a new :term:`strong reference` to
a :ref:`bytes object <bytesobjects>` which must be released
when it is no longer used.
Embedded null bytes are not allowed in the result.
If *obj* is ``NULL``, the function releases a strong reference
stored in the variable referred by *result*.
.. versionadded:: 3.1
.. versionchanged:: 3.6
Accepts a :term:`path-like object`.
To decode file names to :class:`str` during argument parsing, the ``"O&"``
converter should be used, passing :c:func:`PyUnicode_FSDecoder` as the
converter should be used, passing :c:func:`!PyUnicode_FSDecoder` as the
conversion function:
.. c:function:: int PyUnicode_FSDecoder(PyObject* obj, void* result)
ParseTuple converter: decode :class:`bytes` objects -- obtained either
:ref:`PyArg_Parse\* converter <arg-parsing>`: decode :class:`bytes` objects -- obtained either
directly or indirectly through the :class:`os.PathLike` interface -- to
:class:`str` using :c:func:`PyUnicode_DecodeFSDefaultAndSize`; :class:`str`
objects are output as-is. *result* must be a :c:expr:`PyUnicodeObject*` which
must be released when it is no longer used.
objects are output as-is.
*result* must be an address of a C variable of type :c:expr:`PyObject*`
(or :c:expr:`PyUnicodeObject*`).
The variable is set to a new :term:`strong reference` to
a :ref:`Unicode object <unicodeobjects>` which must be released
when it is no longer used.
Embedded null characters are not allowed in the result.
If *obj* is ``NULL``, the function releases a strong reference
stored in the variable referred by *result*.
.. versionadded:: 3.2
Expand Down

0 comments on commit d17ebec

Please sign in to comment.