Skip to content

Commit

Permalink
pythongh-118406: Add signature for sqlite3.Connection objects
Browse files Browse the repository at this point in the history
  • Loading branch information
erlend-aasland committed Apr 30, 2024
1 parent 11f8348 commit d71c737
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Lib/test/test_sqlite3/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,11 @@ def test_connection_resource_warning(self):
del cx
gc_collect()

def test_connection_signature(self):
from inspect import signature
sig = signature(self.cx)
self.assertEqual(str(sig), "(sql, /)")


class UninitialisedConnectionTests(unittest.TestCase):
def setUp(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add signature for :class:`sqlite3.Connection` objects.
7 changes: 7 additions & 0 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -2561,6 +2561,12 @@ set_autocommit(pysqlite_Connection *self, PyObject *val, void *Py_UNUSED(ctx))
return 0;
}

static PyObject *
get_sig(pysqlite_Connection *self, void *Py_UNUSED(ctx))
{
return PyUnicode_FromString("(sql, /)");
}


static const char connection_doc[] =
PyDoc_STR("SQLite database connection object.");
Expand All @@ -2570,6 +2576,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}
};

Expand Down

0 comments on commit d71c737

Please sign in to comment.