Closed
Description
See #93057 (comment)
In sqlite3, both sqlite3.connect
and sqlite3.Connection.__init__
have the same param spec. This has led to the far-from-optimal status quo:
cpython/Modules/_sqlite/module.c
Lines 51 to 69 in d93b4ac
cpython/Modules/_sqlite/connection.c
Lines 215 to 239 in d93b4ac
Instead, we want to be able to do this in connection.c:
/*[clinic input]
sqlite3.Connection.__init__ as pysqlite_connection_init
database: object
timeout: double = 5.0
detect_types: int = 0
isolation_level: IsolationLevel = ""
check_same_thread: bool = True
factory: object(c_default='(PyObject*)clinic_state()->ConnectionType') = ConnectionType
cached_statements as cache_size: int = 128
uri: bool = False
*
autocommit: Autocommit(c_default='LEGACY_TRANSACTION_CONTROL') = sqlite3.LEGACY_TRANSACTION_CONTROL
[clinic start generated code]*/
static int
pysqlite_connection_init_impl(pysqlite_Connection *self, PyObject *database,
double timeout, int detect_types,
const char *isolation_level,
int check_same_thread, PyObject *factory,
int cache_size, int uri,
enum autocommit_mode autocommit)
/*[clinic end generated code: output=cba057313ea7712f input=a0949fb85339104d]*/
{
// __init__ function is here; fast forward ...
}
/*[clinic input]
# Save the clinic output config.
output push
# Create a new destination 'connect' for the docstring and methoddef only.
destination connect new file '{dirname}/clinic/_sqlite3.connect.c.h'
output everything suppress
output docstring_definition connect
output methoddef_define connect
# Now, define the connect function.
sqlite3.connect as pysqlite_connect = sqlite3.Connection.__init__
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=7913cd0b3bfc1b4a]*/
/*[clinic input]
# Restore the clinic output config.
output pop
[clinic start generated code]*/
The methoddef and docstring for sqlite3.connect
could then be included in module.c.
However, to achieve this, we need to teach Argument Clinic how to clone __init__
functions.