-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[C API] Removed private _PyArg_Parser API has no replacement in Python 3.13 #112136
Comments
A code search on
|
These APIs are effectively required for using Notably "Private, but documented, and partially considered part of the stable ABI" is not the same thing as "Private". Removing these functions leaves no API to interact with these documented call mechanisms. Unless you intend to remove Anecdotally, we make extensive use of |
What I'm trying to do here is to list projects using these projects, see how they use the API, and which public API is needed.
Do you have some examples? Which calling convention do you use?
This situation is unfortunate. METH_FASTCALL was created as a private API but apparently, it was adopted outside Python before it was standardized by PEP 590 – Vectorcall: a fast calling protocol for CPython. As the author of
In terms of functions, so far the following functions were mentioned:
Is the number of arguments always a signed |
I don't think we do anything fancy, basically the same straightforward code you would see pop out of argument clinic: // Tiny METH_FASTCALL example function
static PyObject *print_func(PyObject *self,
PyObject *const *args, Py_ssize_t nargs) {
const char *str;
if(!_PyArg_ParseStack(args, nargs, "s", &str))
return NULL;
puts(str);
Py_RETURN_NONE;
} or // Tiny METH_FASTCALL | METH_KEYWORDS example function
static PyObject* prefix_print(PyObject* self, PyObject* const* args,
Py_ssize_t nargs, PyObject* kwnames) {
static const char* _keywords[] = {"", "prefix", NULL};
static _PyArg_Parser _parser = {.keywords = _keywords,
.format = "s|s:prefix_print"};
const char* str;
const char* prefix = NULL;
if(!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, &str,
&prefix))
return NULL;
if(prefix)
printf("%s", prefix);
puts(str);
Py_RETURN_NONE;
} for A quick Ctrl-F shows no one using
Ya 100%. I understand I'm just some random and you're the core dev here, just wanted to raise the objection that breaking this functionality without having that replacement ready doesn't seem like a win to me. The APIs are already internal, there's no stability contract, but if they exist anyway in an unbroken state, what's the harm in leaving them accessible until a replacement is available? As a practical matter if these disappeared we would be replicating the declarations in our own headers for the Python versions where no solutions existed, and that seems like a pointless maintenance burden to push out into the world.
|
@vstinner in case of |
blender also uses |
Restore removed private _PyArg_Parser structure and private _PyArg_ParseTupleAndKeywordsFast() function. Recreate Include/cpython/modsupport.h header file.
Restore removed private _PyArg_Parser structure and private _PyArg_ParseTupleAndKeywordsFast() function. Recreate Include/cpython/modsupport.h header file.
I wrote PR gh-121262 to restore the private _PyArg_Parser structure and the private _PyArg_ParseTupleAndKeywordsFast() function. Is it enough for Blender? |
Restore the private _PyArg_Parser structure and the private _PyArg_ParseTupleAndKeywordsFast() function, previously removed in Python 3.13 alpha 1. Recreate Include/cpython/modsupport.h header file.
@vstinner on a naive grep it looks like it should be enough, but blender at least also uses |
Good. I was only asking for "PyArg" APIs. |
Restore the private _PyArg_Parser structure and the private _PyArg_ParseTupleAndKeywordsFast() function, previously removed in Python 3.13 alpha 1. Recreate Include/cpython/modsupport.h header file.
I restored the removed private _PyArg_Parser structure and the private _PyArg_ParseTupleAndKeywordsFast() function in the change f8373db. I close the issue. |
Restore the private _PyArg_Parser structure and the private _PyArg_ParseTupleAndKeywordsFast() function, previously removed in Python 3.13 alpha 1. Recreate Include/cpython/modsupport.h header file. (cherry picked from commit f8373db) Co-authored-by: Victor Stinner <vstinner@python.org>
gh-112136: Restore removed _PyArg_Parser (GH-121262) Restore the private _PyArg_Parser structure and the private _PyArg_ParseTupleAndKeywordsFast() function, previously removed in Python 3.13 alpha 1. Recreate Include/cpython/modsupport.h header file. (cherry picked from commit f8373db) Co-authored-by: Victor Stinner <vstinner@python.org>
I think this has been prematurely closed as no solution has been provided for the other |
Ok, I reopen the issue. |
Restore the private _PyArg_Parser structure and the private _PyArg_ParseTupleAndKeywordsFast() function, previously removed in Python 3.13 alpha 1. Recreate Include/cpython/modsupport.h header file.
Restore the private _PyArg_Parser structure and the private _PyArg_ParseTupleAndKeywordsFast() function, previously removed in Python 3.13 alpha 1. Recreate Include/cpython/modsupport.h header file.
Oh, I lost track of this issue and we are now past Python 3.13 rc2 release! The next release should be 3.13 final.
Can't you use the internal C API for that? Something like: #define Py_BUILD_CORE_MODULE
#include <Python.h>
#include <pycore_modsupport.h> |
Yep, that's what we're doing. I'm more raising the issue because there should be a blessed replacement. |
The
I failed to design a better replacement. So far, no one else proposed a better replacement. |
I propose to close the issue and leave the situation as it is. You should opt-in for the internal C API if you want to use these APIs sadly. For now, there is no good replacement in the public C API. |
If the official upstream answer is "do not replace" then I agree there's nothing left to do here |
I would be very interested to see a public API to replace these internal C APIs. But so far, nobody managed to propose a better replacement. Time to time, I'm still trying to design a replacement, but I didn't find anything satisfying myself. Maybe a less optimized API should be designed to leak less implementation details. For now, I close the issue. |
pycore_modsupport.h no longer needs pycore_lock.h.
pycore_modsupport.h no longer needs pycore_lock.h.
Copy of @tacaswell's message:
The _PyArg_Parser API is used by Argument Clinic to generate efficient code parsing function arguments.
Since Python 3.12, when targeting Python internals, Argument Clinic initializes
_PyArg_Parser.kwtuple
with singletons objects using the_Py_SINGLETON(name)
API. This API cannot be used outside Python.Private functions with a
_PyArg_Parser
argument:cc @serhiy-storchaka
Linked PRs
The text was updated successfully, but these errors were encountered: