]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.10] bpo-44087: Disallow instantiation of sqlite3.Statement (GH-26567) (GH-26816)
authorErlend Egeberg Aasland <erlend.aasland@innova.no>
Sun, 20 Jun 2021 21:07:31 +0000 (23:07 +0200)
committerGitHub <noreply@github.com>
Sun, 20 Jun 2021 21:07:31 +0000 (22:07 +0100)
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
Lib/sqlite3/test/dbapi.py
Modules/_sqlite/statement.c

index 39c9bf5b61143db5f221d1e0b4fe0509d5d86d75..0716e656a7f26f60cea1a32e3ae10f4e0f03cfcc 100644 (file)
@@ -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):
 
index 2fd9ba3ca801ad7b49861923b8f63b9543ebafcf..c875eb0cd74a406150b70e2e8292a5ea8ea03a99 100644 (file)
@@ -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;