Skip to content

Commit 2556771

Browse files
vstinnerencukou
andauthored
PEP 743: Make the macro a simple boolean (#4595)
* Remove the version value. * Rename the macro to Py_OMIT_LEGACY_API Co-authored-by: Petr Viktorin <[email protected]>
1 parent fe91e2b commit 2556771

File tree

1 file changed

+16
-31
lines changed

1 file changed

+16
-31
lines changed

peps/pep-0743.rst

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
PEP: 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
33
Author: Victor Stinner <[email protected]>,
44
Petr Viktorin <[email protected]>,
55
PEP-Delegate: C API Working Group
66
Discussions-To: https://discuss.python.org/t/pep-743-add-py-compat-api-version-to-the-python-c-api-take-2/59323
77
Status: Draft
88
Type: Standards Track
99
Created: 11-Mar-2024
10-
Python-Version: 3.14
10+
Python-Version: 3.15
1111

1212
.. highlight:: c
1313

1414

1515
Abstract
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
1919
soft-deprecated symbols, allowing users to opt out of using API with known
2020
issues that other API solves.
21-
The macro is versioned, allowing users to update (or not) on their own pace.
2221

2322
Also, add namespaced alternatives for API without the ``Py_`` prefix,
2423
and soft-deprecate the original names.
@@ -81,7 +80,7 @@ It might be be sufficient to leave this to third-party linters.
8180
For that we'd need a good way to expose a list of (soft-)deprecated
8281
API to such linters.
8382
While 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.
8584
Unlike Python, C makes it rather easy to limit available API -- for a whole
8685
project or for each individual source file -- by having users define
8786
an “opt-in” macro.
@@ -91,11 +90,6 @@ available API to a subset that compiles to stable ABI. (In hindsight, we should
9190
have used a different macro name for that particular kind of limiting, but it's
9291
too 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-
9993
To be clear, this mechanism is *not* a replacement for deprecation.
10094
Deprecation is for API that prevents new features or optimizations, or
10195
presents a security risk or maintenance burden.
@@ -126,7 +120,7 @@ third-party libraries.
126120
Specification
127121
=============
128122

129-
We introduce a ``Py_COMPAT_API_VERSION`` macro.
123+
We introduce a ``Py_OMIT_LEGACY_API`` macro.
130124
If 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.
142136
In rare cases, entries can be removed (i.e. made available for use) at any
143137
time.
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

152140
Requirements 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
168156
replaced by a better alternative.
169157
API without a replacement should generally be deprecated instead.
170158

171159

172160
Location
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
176164
a new header, ``Include/legacy.h``.
177165

178166
This 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.
200188
Initial 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

347334
If any of these proposed replacements, or associated documentation,
348335
are 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
357344
TBD
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-
367347
Backwards Compatibility
368348
=======================
369349

370350
The macro is backwards compatible.
371351
Developers can introduce and update the macro on their own pace, potentially
372352
for 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

375360
Discussions
376361
===========

0 commit comments

Comments
 (0)