From ccc95c7b4799570c2d7e4de3d579860ad833e1f8 Mon Sep 17 00:00:00 2001 From: Erlend Egeberg Aasland Date: Sun, 20 Jun 2021 23:07:31 +0200 Subject: [3.10] bpo-44087: Disallow instantiation of sqlite3.Statement (GH-26567) (GH-26816) Co-authored-by: Erlend Egeberg Aasland --- Lib/sqlite3/test/dbapi.py | 5 +++++ Modules/_sqlite/statement.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Lib/sqlite3/test/dbapi.py b/Lib/sqlite3/test/dbapi.py index 39c9bf5..0716e65 100644 --- a/Lib/sqlite3/test/dbapi.py +++ b/Lib/sqlite3/test/dbapi.py @@ -92,6 +92,11 @@ class ModuleTests(unittest.TestCase): sqlite.enable_shared_cache(enable) self.assertIn("dbapi.py", cm.filename) + def test_disallow_instantiation(self): + cx = sqlite.connect(":memory:") + tp = type(cx("select 1")) + self.assertRaises(TypeError, tp) + class ConnectionTests(unittest.TestCase): diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c index 2fd9ba3..c875eb0 100644 --- a/Modules/_sqlite/statement.c +++ b/Modules/_sqlite/statement.c @@ -509,7 +509,7 @@ static PyType_Spec stmt_spec = { .name = MODULE_NAME ".Statement", .basicsize = sizeof(pysqlite_Statement), .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | - Py_TPFLAGS_IMMUTABLETYPE), + Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_DISALLOW_INSTANTIATION), .slots = stmt_slots, }; PyTypeObject *pysqlite_StatementType = NULL; -- cgit v0.12