gh-133595: Clean up sqlite3.Connection APIs (GH-133605)

* All parameters of sqlite3.connect() except "database" are now keyword-only.
* The first three parameters of methods create_function() and
  create_aggregate() are now positional-only.
* The first parameter of methods set_authorizer(), set_progress_handler()
  and set_trace_callback() is now positional-only.
This commit is contained in:
Serhiy Storchaka 2025-05-08 15:42:00 +03:00 committed by GitHub
parent 2561e148ec
commit dcf93c4c93
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 117 additions and 445 deletions

View file

@ -60,26 +60,16 @@ pysqlite_connect(PyObject *module, PyObject *const *args, Py_ssize_t nargsf,
pysqlite_state *state = pysqlite_get_state(module);
PyObject *factory = (PyObject *)state->ConnectionType;
static const int FACTORY_POS = 5;
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
if (nargs > 1 && nargs <= 8) {
if (PyErr_WarnEx(PyExc_DeprecationWarning,
"Passing more than 1 positional argument to sqlite3.connect()"
" is deprecated. Parameters 'timeout', 'detect_types', "
"'isolation_level', 'check_same_thread', 'factory', "
"'cached_statements' and 'uri' will become keyword-only "
"parameters in Python 3.15.", 1))
{
return NULL;
}
if (nargs > 1) {
PyErr_Format(PyExc_TypeError,
"connect() takes at most 1 positional arguments (%zd given)", nargs);
return NULL;
}
if (nargs > FACTORY_POS) {
factory = args[FACTORY_POS];
}
else if (kwnames != NULL) {
if (kwnames != NULL) {
for (Py_ssize_t i = 0; i < PyTuple_GET_SIZE(kwnames); i++) {
PyObject *item = PyTuple_GET_ITEM(kwnames, i); // borrowed ref.
if (PyUnicode_CompareWithASCIIString(item, "factory") == 0) {
if (PyUnicode_EqualToUTF8(item, "factory")) {
factory = args[nargs + i];
break;
}