Skip to content
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

Implement inspect.signature() for sqlite3 connection object #118406

Closed
serhiy-storchaka opened this issue Apr 29, 2024 · 4 comments · Fixed by #118428
Closed

Implement inspect.signature() for sqlite3 connection object #118406

serhiy-storchaka opened this issue Apr 29, 2024 · 4 comments · Fixed by #118428
Labels
3.13 bugs and security fixes topic-sqlite3 type-feature A feature request or enhancement

Comments

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Apr 29, 2024

Feature or enhancement

sqlite3.connection() returns a custom callable object. But inspect.signature() returns a generic <Signature (*args, **kwargs)> for it:

>>> import inspect, sqlite3
>>> con = sqlite3.connect(':memory:')
>>> con('select 1')
<sqlite3.Statement object at 0x7f76842d2fd0>
>>> inspect.signature(con)
<Signature (*args, **kwargs)>

This issue is similar to #118285 and #118402.

Linked PRs

@serhiy-storchaka serhiy-storchaka added type-feature A feature request or enhancement topic-sqlite3 3.13 bugs and security fixes labels Apr 29, 2024
@erlend-aasland
Copy link
Contributor

This is interesting. At first, I thought a simple patch a la this could fix it:

diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 74984ca536..f49bcd0b49 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -2561,6 +2561,13 @@ set_autocommit(pysqlite_Connection *self, PyObject *val, void *Py_UNUSED(ctx))
     return 0;
 }
 
+#include "clinic/_sqlite3.connect.c.h"
+static PyObject *
+get_sig(pysqlite_Connection *self, void *Py_UNUSED(ctx))
+{
+    return PyUnicode_FromString(pysqlite_connect__doc__);
+}
+
 
 static const char connection_doc[] =
 PyDoc_STR("SQLite database connection object.");
@@ -2570,6 +2577,7 @@ static PyGetSetDef connection_getset[] = {
     {"total_changes",  (getter)pysqlite_connection_get_total_changes, (setter)0},
     {"in_transaction",  (getter)pysqlite_connection_get_in_transaction, (setter)0},
     {"autocommit",  (getter)get_autocommit, (setter)set_autocommit},
+    {"__text_signature__", (getter)get_sig, (setter)0},
     {NULL}
 };
 

However, inspect.signature() will not accept that whole docstring. Manually spelling out only the signature part does not work either. Do you have a solution in hand?

@serhiy-storchaka
Copy link
Member Author

Simply return "(sql)" (or "(sql, /)"?).

I have not solved this simple issue only because it needs tests, and searching in which of many of test_sqlite3 files is more suitable takes time.

@serhiy-storchaka
Copy link
Member Author

See also #118427 for example.

@erlend-aasland
Copy link
Contributor

Ah, I used the incorrect signature. I'll propose a PR soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes topic-sqlite3 type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants