Skip to content
19 changes: 19 additions & 0 deletions Doc/c-api/file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,22 @@ 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.


Deprecated API
^^^^^^^^^^^^^^


These are :term:`soft deprecated` APIs that were included in Python's C API
by mistake. They are documented solely for completeness; use other
``PyFile*`` APIs instead.

.. c:function:: PyObject *PyFile_NewStdPrinter(int fd)

Use :c:func:`PyFile_FromFd` with defaults (``fd, NULL, "w", -1, NULL, NULL, NULL, 0``) instead.

.. c:var:: PyTypeObject PyStdPrinter_Type

Type of file-like objects used internally at Python startup when :py:mod:`io` is
not yet available.
Use Python :py:func:`open` or :c:func:`PyFile_FromFd` to create file objects instead.
11 changes: 11 additions & 0 deletions Doc/c-api/gen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,14 @@ than explicitly calling :c:func:`PyGen_New` or :c:func:`PyGen_NewWithQualName`.
with ``__name__`` and ``__qualname__`` set to *name* and *qualname*.
A reference to *frame* is stolen by this function. The *frame* argument
must not be ``NULL``.


Deprecated API
^^^^^^^^^^^^^^

.. c:macro:: PyAsyncGenASend_CheckExact(op)

This is a :term:`soft deprecated` API that was included in Python's C API
by mistake.

It is solely here for completeness; do not use this API.
28 changes: 28 additions & 0 deletions Doc/c-api/long.rst
Original file line number Diff line number Diff line change
Expand Up @@ -855,3 +855,31 @@ The :c:type:`PyLongWriter` API can be used to import an integer.
If *writer* is ``NULL``, no operation is performed.

The writer instance and the *digits* array are invalid after the call.


Deprecated API
^^^^^^^^^^^^^^

These macros are :term:`soft deprecated`. They describe parameters
of the internal representation of :c:type:`PyLongObject` instances.

Use :c:func:`PyLong_GetNativeLayout` instead, along with :c:func:`PyLong_Export`
to read integer data or :c:type:`PyLongWriter` to write it.
These currently use the same layout, but are designed to continue working correctly
even if CPython's internal integer representation changes.


.. c:macro:: PyLong_SHIFT

This is equivalent to :c:member:`~PyLongLayout.bits_per_digit` in
the output of :c:func:`PyLong_GetNativeLayout`.


.. c:macro:: PyLong_BASE

This is currently equivalent to :c:expr:`1 << PyLong_SHIFT`.


.. c:macro:: PyLong_MASK

This is currently equivalent to :c:expr:`(1 << PyLong_SHIFT) - 1`
12 changes: 12 additions & 0 deletions Doc/c-api/set.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,15 @@ subtypes but not for instances of :class:`frozenset` or its subtypes.
Empty an existing set of all elements. Return ``0`` on
success. Return ``-1`` and raise :exc:`SystemError` if *set* is not an instance of
:class:`set` or its subtype.


Deprecated API
^^^^^^^^^^^^^^

.. c:macro:: PySet_MINSIZE

This is a :term:`soft deprecated` constant representing the size of a
preallocated table inside :c:type:`PySetObject` instances.

This is documented solely for completeness and not useful to users in any
way. If looking for the size of a set, use :c:func:`PySet_Size` instead.
Comment on lines +176 to +180
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is a user supposed to do if they find PySet_MINSIZE somewhere?

This is indeed not obvious. All the more reason for the docs to mention it, if we want to add docs.

What about something like:

Suggested change
This is a :term:`soft deprecated` constant representing the size of a
preallocated table inside :c:type:`PySetObject` instances.
This is documented solely for completeness and not useful to users in any
way. If looking for the size of a set, use :c:func:`PySet_Size` instead.
A :term:`soft deprecated` constant representing the size of an internal
preallocated table inside :c:type:`PySetObject` instances.
This is documented solely for completeness, as there are no guarantees
that a given version of CPython uses preallocated tables with a fixed
size.
In code that does not deal with unstable set internals,
:c:macro:`!PySet_MINSIZE` can be replaced with a small constant like ``8``.
If looking for the size of a set, use :c:func:`PySet_Size` instead.
.. deprecated:: next
The constant is :term:`soft deprecated`.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too fond of using .. deprecated for this, because the next (or whatever version we put in there) would imply that it's fine to use for earlier versions. We don't want people using this on any version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair.
On the other hand, without .. deprecated, automated tools won't be able to tell that these are deprecated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, I don't think our documentation is sufficient for automated tools yet. (For example, we document a bunch of macros as functions, which would break if used to generate bindings.) I do agree that we should eventually get C API documentation to that point, but that's a project I plan to work on once #141004 is done.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think .. deprecated is better in the mean time. But I won't block the PR on that :)

Loading