Skip to content

Commit 0e0d51c

Browse files
ZeroIntensityencukouvstinner
authored
gh-141004: Document several soft-deprecated C APIs (GH-141634)
Co-authored-by: Petr Viktorin <encukou@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent a471a32 commit 0e0d51c

File tree

5 files changed

+76
-10
lines changed

5 files changed

+76
-10
lines changed

Doc/c-api/file.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,22 @@ the :mod:`io` APIs instead.
131131
132132
Write string *s* to file object *p*. Return ``0`` on success or ``-1`` on
133133
failure; the appropriate exception will be set.
134+
135+
136+
Deprecated API
137+
^^^^^^^^^^^^^^
138+
139+
140+
These are :term:`soft deprecated` APIs that were included in Python's C API
141+
by mistake. They are documented solely for completeness; use other
142+
``PyFile*`` APIs instead.
143+
144+
.. c:function:: PyObject *PyFile_NewStdPrinter(int fd)
145+
146+
Use :c:func:`PyFile_FromFd` with defaults (``fd, NULL, "w", -1, NULL, NULL, NULL, 0``) instead.
147+
148+
.. c:var:: PyTypeObject PyStdPrinter_Type
149+
150+
Type of file-like objects used internally at Python startup when :py:mod:`io` is
151+
not yet available.
152+
Use Python :py:func:`open` or :c:func:`PyFile_FromFd` to create file objects instead.

Doc/c-api/gen.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ than explicitly calling :c:func:`PyGen_New` or :c:func:`PyGen_NewWithQualName`.
4545
A reference to *frame* is stolen by this function. The *frame* argument
4646
must not be ``NULL``.
4747
48+
4849
.. c:function:: PyCodeObject* PyGen_GetCode(PyGenObject *gen)
4950
5051
Return a new :term:`strong reference` to the code object wrapped by *gen*.
@@ -82,3 +83,14 @@ Asynchronous Generator Objects
8283
This function always succeeds.
8384
8485
.. versionadded:: 3.6
86+
87+
88+
Deprecated API
89+
^^^^^^^^^^^^^^
90+
91+
.. c:macro:: PyAsyncGenASend_CheckExact(op)
92+
93+
This is a :term:`soft deprecated` API that was included in Python's C API
94+
by mistake.
95+
96+
It is solely here for completeness; do not use this API.

Doc/c-api/long.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,3 +855,31 @@ The :c:type:`PyLongWriter` API can be used to import an integer.
855855
If *writer* is ``NULL``, no operation is performed.
856856
857857
The writer instance and the *digits* array are invalid after the call.
858+
859+
860+
Deprecated API
861+
^^^^^^^^^^^^^^
862+
863+
These macros are :term:`soft deprecated`. They describe parameters
864+
of the internal representation of :c:type:`PyLongObject` instances.
865+
866+
Use :c:func:`PyLong_GetNativeLayout` instead, along with :c:func:`PyLong_Export`
867+
to read integer data or :c:type:`PyLongWriter` to write it.
868+
These currently use the same layout, but are designed to continue working correctly
869+
even if CPython's internal integer representation changes.
870+
871+
872+
.. c:macro:: PyLong_SHIFT
873+
874+
This is equivalent to :c:member:`~PyLongLayout.bits_per_digit` in
875+
the output of :c:func:`PyLong_GetNativeLayout`.
876+
877+
878+
.. c:macro:: PyLong_BASE
879+
880+
This is currently equivalent to :c:expr:`1 << PyLong_SHIFT`.
881+
882+
883+
.. c:macro:: PyLong_MASK
884+
885+
This is currently equivalent to :c:expr:`(1 << PyLong_SHIFT) - 1`

Doc/c-api/set.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,20 @@ subtypes but not for instances of :class:`frozenset` or its subtypes.
166166
Empty an existing set of all elements. Return ``0`` on
167167
success. Return ``-1`` and raise :exc:`SystemError` if *set* is not an instance of
168168
:class:`set` or its subtype.
169+
170+
171+
Deprecated API
172+
^^^^^^^^^^^^^^
173+
174+
.. c:macro:: PySet_MINSIZE
175+
176+
A :term:`soft deprecated` constant representing the size of an internal
177+
preallocated table inside :c:type:`PySetObject` instances.
178+
179+
This is documented solely for completeness, as there are no guarantees
180+
that a given version of CPython uses preallocated tables with a fixed
181+
size.
182+
In code that does not deal with unstable set internals,
183+
:c:macro:`!PySet_MINSIZE` can be replaced with a small constant like ``8``.
184+
185+
If looking for the size of a set, use :c:func:`PySet_Size` instead.

Tools/check-c-api-docs/ignored_c_api.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,11 @@ PyDescr_NAME
7171
PyDescr_TYPE
7272
PyWrapperFlag_KEYWORDS
7373
# cpython/fileobject.h
74-
PyFile_NewStdPrinter
75-
PyStdPrinter_Type
7674
Py_UniversalNewlineFgets
77-
# cpython/setobject.h
78-
PySet_MINSIZE
7975
# cpython/ceval.h
8076
PyUnstable_CopyPerfMapFile
8177
PyUnstable_PerfTrampoline_CompileCode
8278
PyUnstable_PerfTrampoline_SetPersistAfterFork
83-
# cpython/genobject.h
84-
PyAsyncGenASend_CheckExact
85-
# cpython/longintrepr.h
86-
PyLong_BASE
87-
PyLong_MASK
88-
PyLong_SHIFT
8979
# cpython/pyerrors.h
9080
PyException_HEAD
9181
# cpython/pyframe.h

0 commit comments

Comments
 (0)