gh-107704: Argument Clinic: add support for deprecating keyword use of parameters (GH-107984)

It is now possible to deprecate passing keyword arguments for
keyword-or-positional parameters with Argument Clinic, using the new
'/ [from X.Y]' syntax.
(To be read as "positional-only from Python version X.Y")

Co-authored-by: Erlend E. Aasland <erlend@python.org>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
Serhiy Storchaka 2023-08-19 10:13:35 +03:00 committed by GitHub
parent eb953d6e44
commit 2f311437cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 2993 additions and 1345 deletions

View file

@ -16,6 +16,17 @@ pysqlite_connection_init_impl(pysqlite_Connection *self, PyObject *database,
int cache_size, int uri,
enum autocommit_mode autocommit);
// Emit compiler warnings when we get to Python 3.15.
#if PY_VERSION_HEX >= 0x030f00C0
# error "Update the clinic input of '_sqlite3.Connection.__init__'."
#elif PY_VERSION_HEX >= 0x030f00A0
# ifdef _MSC_VER
# pragma message ("Update the clinic input of '_sqlite3.Connection.__init__'.")
# else
# warning "Update the clinic input of '_sqlite3.Connection.__init__'."
# endif
#endif
static int
pysqlite_connection_init(PyObject *self, PyObject *args, PyObject *kwargs)
{
@ -59,28 +70,6 @@ pysqlite_connection_init(PyObject *self, PyObject *args, PyObject *kwargs)
int uri = 0;
enum autocommit_mode autocommit = LEGACY_TRANSACTION_CONTROL;
// Emit compiler warnings when we get to Python 3.15.
#if PY_VERSION_HEX >= 0x030f00C0
# error \
"In connection.c, update parameter(s) 'timeout', 'detect_types', " \
"'isolation_level', 'check_same_thread', 'factory', " \
"'cached_statements' and 'uri' in the clinic input of " \
"'_sqlite3.Connection.__init__' to be keyword-only."
#elif PY_VERSION_HEX >= 0x030f00A0
# ifdef _MSC_VER
# pragma message ( \
"In connection.c, update parameter(s) 'timeout', 'detect_types', " \
"'isolation_level', 'check_same_thread', 'factory', " \
"'cached_statements' and 'uri' in the clinic input of " \
"'_sqlite3.Connection.__init__' to be keyword-only.")
# else
# warning \
"In connection.c, update parameter(s) 'timeout', 'detect_types', " \
"'isolation_level', 'check_same_thread', 'factory', " \
"'cached_statements' and 'uri' in the clinic input of " \
"'_sqlite3.Connection.__init__' to be keyword-only."
# endif
#endif
if (nargs > 1 && nargs <= 8) {
if (PyErr_WarnEx(PyExc_DeprecationWarning,
"Passing more than 1 positional argument to _sqlite3.Connection()"
@ -89,7 +78,7 @@ pysqlite_connection_init(PyObject *self, PyObject *args, PyObject *kwargs)
"'cached_statements' and 'uri' will become keyword-only "
"parameters in Python 3.15.", 1))
{
goto exit;
goto exit;
}
}
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 8, 0, argsbuf);
@ -1692,4 +1681,4 @@ exit:
#ifndef DESERIALIZE_METHODDEF
#define DESERIALIZE_METHODDEF
#endif /* !defined(DESERIALIZE_METHODDEF) */
/*[clinic end generated code: output=5a05e5294ad9d2ce input=a9049054013a1b77]*/
/*[clinic end generated code: output=0ad9d55977a51b8f input=a9049054013a1b77]*/