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

index 2924231245460c9118d60e54997faca4b0221666..e8bd8c59947cdd666e453c80d9285fcd6ea70a2a 100644 (file)
@@ -26,6 +26,7 @@ import sys
 import threading
 import unittest
 
+from test.support import check_disallow_instantiation
 from test.support.os_helper import TESTFN, unlink
 from test.support import threading_helper
 
@@ -105,6 +106,10 @@ class ModuleTests(unittest.TestCase):
                 sqlite.enable_shared_cache(enable)
             self.assertIn("dbapi.py", cm.filename)
 
+    def test_disallow_instantiation(self):
+        cx = sqlite.connect(":memory:")
+        check_disallow_instantiation(self, type(cx("select 1")))
+
 
 class ConnectionTests(unittest.TestCase):
 
index 3960b21c85943534f3b73db9e7576f83dec8b57f..fcf13809763f3eb4c70887e473b477118c4e7dc8 100644 (file)
@@ -503,7 +503,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,
 };