You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The Python C API should only define macros with a name starting wit Py #157695
Currently, the Python C API defines 472 macros with a name which doesn't start with Py, PY, _Py or _PY prefix.
I propose adding a check to prevent adding new macros which doesn't respect this convention. Existing invalid names will be added to an ignore list for now.
The following Include/ header files are not included by Python.h and defines many macros which don't start with Py prefix:
opcode.h
opcode_ids.h
errcode.h
osdefs.h
structmember.h
To clean up the C API, a simple move would be to move these header files to the internal C API. Problem: they are actually used in the wild (well, as usual ;-)).
I checked PyPI top 15,000 projects (at 2026-09-17) to find projects including these header files.
Projects (10) including opcode.h:
coverage (7.16.1)
crosshair_tool (0.0.110)
ddtrace (4.15.0)
nuitka (4.2.1)
pygments (2.21.0)
pyobjc_core (12.2.2)
pywinpty (3.0.5)
rook (0.1.209)
slipcover (1.1.0)
yappi (1.7.6)
I found no project including errcode.h.
Projects (4) including osdefs.h:
freeze_core (0.7.5)
mod_wsgi (6.0.6)
nuitka (4.2.1)
scandir (1.10.0)
Projects (169) including structmember.h:
MySQL-python (1.2.5)
PyICU-binary (2.7.4)
PyQt5 (5.15.11)
... the list is quite long, I prefer to truncate it! :-)
For example, I searched for include\s+["<]errcode\.h[">] for errcode.h include.
structmember.h has been deprecated in docs (which we now call soft deprectation) since 3.12. See also the comment in the header.
IMO, exposing legacy non-Py_-prefixed names via an opt-in #include is perfectly fine.
Activity
vstinner commentedon Sep 17, 2026
The following Include/ header files are not included by Python.h and defines many macros which don't start with
Pyprefix:To clean up the C API, a simple move would be to move these header files to the internal C API. Problem: they are actually used in the wild (well, as usual ;-)).
I checked PyPI top 15,000 projects (at 2026-09-17) to find projects including these header files.
Projects (10) including opcode.h:
I found no project including errcode.h.
Projects (4) including osdefs.h:
Projects (169) including structmember.h:
For example, I searched for
include\s+["<]errcode\.h[">]for errcode.h include.vstinner commentedon Sep 17, 2026
This check is similar to "make smelly" which fails if libpython exports symbols with a name which doesn't start with "Py".
vstinner commentedon Sep 17, 2026
cc @encukou
vstinner commentedon Sep 17, 2026
See issue gh-149685 "Use _Py prefix for private C API added in 3.15" for a recent change (last May) about a similar issue.
gh-157695: Rename HAVE_FLOAT16 macro to _Py_HAVE_FLOAT16 (#157752)
gh-157695: Check that C API macros start with "Py" (#157696)
gh-157695: Rename HAVE_ICONV to _Py_HAVE_ICONV (#157821)
gh-157695: Rename HAVE_ACOSPI to _Py_HAVE_ACOSPI (#157858)
Locked-chess-official commentedon Sep 22, 2026
I have an immature idea: For configures, we can move the private configure macros into a new file named
pycore_pyconfig.hencukou commentedon Sep 22, 2026
structmember.hhas been deprecated in docs (which we now call soft deprectation) since 3.12. See also the comment in the header.IMO, exposing legacy non-
Py_-prefixed names via an opt-in#includeis perfectly fine.vstinner commentedon Sep 22, 2026
I'm not sure that autotools support multiple output files where some macros are defined in a file, and other macros are defined in another file.
configure.acusesAC_CONFIG_HEADERS([pyconfig.h]).5 remaining items
gh-157695: Parse also _Py_HAVE_xxx variables in sysconfig (#158926)
[3.15] gh-158893: Make os.strerror() thread-safe (#159120)
[3.15] pythongh-158893: Make os.strerror() thread-safe (python#159120)
[3.14] gh-158893: Make os.strerror() thread-safe (#159120) (#159145)
gh-157695: Rename HAVE_GETDENTS64 to _Py_HAVE_GETDENTS64 (#162184)
vstinner commentedon Nov 18, 2026
The initial issue has been fixed by adding
Tools/build/check_capi_macros.pyscript to the main branch. I close the issue.pythongh-157695: Make HAVE_CURSES_xxx macros private
pythongh-157695: Rename HAVE_RL_CHANGE_ENVIRONMENT macro
pythongh-157695: Make HAVE_RL_CHANGE_ENVIRONMENT macro private
gh-157695: Make HAVE_RL_CHANGE_ENVIRONMENT macro private (#162213)
gh-157695: Make HAVE_CURSES_xxx macros private (#162212)