
Am 4. Juni 2020 15:56:54 MESZ schrieb Victor Stinner:
One option is to copy/paste compatibility macros like Py_SET_SIZE() for old Python versions directly in the C code of these extensions. It avoids depending on something external. It's a variant of having a vendored copy of an hypothetical PythonCompat.h header file.
By the way, it's also how Cython handles backward compatibility.
And IMHO the only really reliable way to do it. Cython is admittedly a bit excessive here (we implement and backport most recent Python features and still support Py2.7), but most user code should have a somewhat small set of forward dependencies like the above. As long as it's clear when these were added, it's easy to copy over code snippets one by one and guard them with PY_VERSION_HEX. Old Python versions don't change anymore, so copying new code into old versions is a very safe thing to do, as long as you then switch to the real thing for the future.
Now, whether this is done via a header file that users can copy over entirely or selectively, or by documenting newly added stuff in a way that makes it easy to find and copy, I don't mind. I personally think it's easier to keep these things under local VC rather than as a dependency, but that might just be me.
I think it could be helpful if CPython maintained such a header file in its repo, with the appropriate version guards in it. Then users can decide whether they want to copy the whole file or just bits from it.
Stefan