11PEP: 743
2- Title: Add Py_COMPAT_API_VERSION to the Python C API
2+ Title: Add Py_OMIT_LEGACY_API to the Python C API
33Author: Victor Stinner <
[email protected] >,
44 Petr Viktorin <
[email protected] >,
55PEP-Delegate: C API Working Group
66Discussions-To: https://discuss.python.org/t/pep-743-add-py-compat-api-version-to-the-python-c-api-take-2/59323
77Status: Draft
88Type: Standards Track
99Created: 11-Mar-2024
10- Python-Version: 3.14
10+ Python-Version: 3.15
1111
1212.. highlight :: c
1313
1414
1515Abstract
1616========
1717
18- Add ``Py_COMPAT_API_VERSION `` C macro that hides some deprecated and
18+ Add ``Py_OMIT_LEGACY_API `` C macro that hides deprecated and
1919soft-deprecated symbols, allowing users to opt out of using API with known
2020issues that other API solves.
21- The macro is versioned, allowing users to update (or not) on their own pace.
2221
2322Also, add namespaced alternatives for API without the ``Py_ `` prefix,
2423and soft-deprecate the original names.
@@ -81,7 +80,7 @@ It might be be sufficient to leave this to third-party linters.
8180For that we'd need a good way to expose a list of (soft-)deprecated
8281API to such linters.
8382While adding that, we can -- rather easily -- do the linter's job directly
84- in CPython headers, avoiding the neel for an extra tool.
83+ in CPython headers, avoiding the need for an extra tool.
8584Unlike Python, C makes it rather easy to limit available API -- for a whole
8685project or for each individual source file -- by having users define
8786an “opt-in” macro.
@@ -91,11 +90,6 @@ available API to a subset that compiles to stable ABI. (In hindsight, we should
9190have used a different macro name for that particular kind of limiting, but it's
9291too late to change that now.)
9392
94- To prevent working code from breaking as we identify more “undesirable” API
95- and add safer alternatives to it, the opt-in macro should be *versioned *.
96- Users can choose a version they need based on their compatibility requirements,
97- and update it at their own pace.
98-
9993To be clear, this mechanism is *not * a replacement for deprecation.
10094Deprecation is for API that prevents new features or optimizations, or
10195presents a security risk or maintenance burden.
@@ -126,7 +120,7 @@ third-party libraries.
126120Specification
127121=============
128122
129- We introduce a ``Py_COMPAT_API_VERSION `` macro.
123+ We introduce a ``Py_OMIT_LEGACY_API `` macro.
130124If this macro is defined before ``#include <Python.h> ``, some API definitions
131125-- as described below -- will be omitted from the Python header files.
132126
@@ -142,17 +136,11 @@ of CPython, and is finalized in each 3.x.0 Beta 1 release.
142136In rare cases, entries can be removed (i.e. made available for use) at any
143137time.
144138
145- The macro should be defined to a version in the format used by
146- ``PY_VERSION_HEX ``, with the “micro”, “release” and “serial” fields
147- set to zero.
148- For example, to omit API deemed undesirable in 3.14.0b1, users should define
149- ``Py_COMPAT_API_VERSION `` to ``0x030e0000 ``.
150-
151139
152140Requirements for omitted API
153141----------------------------
154142
155- An API that is omitted with ``Py_COMPAT_API_VERSION `` must:
143+ An API that is omitted with ``Py_OMIT_LEGACY_API `` must:
156144
157145- be soft-deprecated (see :pep: `387 `);
158146- for all known use cases of the API, have a documented alternative
@@ -164,15 +152,15 @@ An API that is omitted with ``Py_COMPAT_API_VERSION`` must:
164152- be approved by the C API working group. (The WG may give blanket approvals
165153 for groups of related API; see *Initial set * below for examples.)
166154
167- Note that ``Py_COMPAT_API_VERSION `` is meant for API that can be trivially
155+ Note that ``Py_OMIT_LEGACY_API `` is meant for API that can be trivially
168156replaced by a better alternative.
169157API without a replacement should generally be deprecated instead.
170158
171159
172160Location
173161--------
174162
175- All API definitions omitted by ``Py_COMPAT_API_VERSION `` will be moved to
163+ All API definitions omitted by ``Py_OMIT_LEGACY_API `` will be moved to
176164a new header, ``Include/legacy.h ``.
177165
178166This is meant to help linter authors compile lists, so they can flag the API
@@ -200,8 +188,7 @@ Exceptions are possible if there is a good reason for them.
200188Initial set
201189-----------
202190
203- The following API will be omitted with ``Py_COMPAT_API_VERSION `` set to
204- ``0x030e0000 `` (3.14) or greater:
191+ The following API will be omitted with ``Py_OMIT_LEGACY_API `` set:
205192
206193- Omit API returning borrowed references:
207194
@@ -289,7 +276,7 @@ The following API will be omitted with ``Py_COMPAT_API_VERSION`` set to
289276
290277 The header file ``structmember.h ``, which is not included from ``<Python.h> ``
291278 and must be included separately, will ``#error `` if
292- ``Py_COMPAT_API_VERSION `` is defined.
279+ ``Py_OMIT_LEGACY_API `` is defined.
293280 This affects the following API:
294281
295282 ==================================== ==============================
@@ -346,7 +333,7 @@ The following API will be omitted with ``Py_COMPAT_API_VERSION`` set to
346333
347334If any of these proposed replacements, or associated documentation,
348335are not added in time for 3.14.0b1, they'll be omitted with later versions
349- of ``Py_COMPAT_API_VERSION ``.
336+ of ``Py_OMIT_LEGACY_API ``.
350337(We expect this for macros generated by ``configure ``: ``HAVE_* ``, ``WITH_* ``,
351338``ALIGNOF_* ``, ``SIZEOF_* ``, and several without a common prefix.)
352339
@@ -357,20 +344,18 @@ Implementation
357344TBD
358345
359346
360- Open issues
361- ===========
362-
363- The name ``Py_COMPAT_API_VERSION `` was taken from the earlier PEP;
364- it doesn't fit this version.
365-
366-
367347Backwards Compatibility
368348=======================
369349
370350The macro is backwards compatible.
371351Developers can introduce and update the macro on their own pace, potentially
372352for one source file at a time.
373353
354+ Future versions of CPython may add more API to the set that
355+ ``Py_OMIT_LEGACY_API `` hides, breaking user code.
356+ The fix is to undefine the macro (which is safe to do) or rework the
357+ code.
358+
374359
375360Discussions
376361===========
0 commit comments