While looking into some sys module details for the discussion in PEP 2026: Calendar versioning for Python I stumbled across of a piece of C API arcana I don’t recall ever encountering before: the PYTHON_API_VERSION C #define and the corresponding sys.api_version attribute.
The macro definition is in modsupport.h and was last updated in 2006 (when it was set to its current value of 1013).
The C API module create docs do mention the APIs that accept an API version (e.g. see Module Objects — Python 3.12.4 documentation ), but mainly just to advise against using them.
Since the stable ABI has been introduced, we can’t actually change this number any more, since any module built against an older version using the stable ABI would start emitting runtime warnings.
Actually getting rid of these entirely is almost certainly more trouble than it would be worth, but updating the docs (and code comments) to say that they’re kept solely for backwards compatibility, haven’t changed since Python 2.6, and won’t ever change again is potentially more reasonable.
The macro injects a version check “transparently” – i.e. if you write PyModule_Create, you’re actually calling PyModule_Create2 with the right argument. AFAIK, the warning in the docs is only against using PyModule_Create2directly.
(Since this involves macros, wrappers for non-C/C++ languages might do something similar – or not since the version check doesn’t do much nowadays.)
“Soft deprecation”: just a note in the docs that this mechanism is not necessary any more. (No need for any warnings, IMO.)
Revive the mechanism:
Identifiyng the ABI (and checking the identifier) would need to be more involved today: it’d need to be either CPython version or minimum stable ABI version, plus any settings that affect the ABI (see a recent topic on this).
Document that PyModule_Create is a macro that calls PyModule_Create2, and give enough information to allow non-C wrappers to reimplement the macro.
Use the same mechanism in a “chokepoint” for stable ABI extensions (PyModuleDef_Init).