[3.10] bpo-44087: Disallow instantiation of sqlite3.Statement (GH-26567) (GH-26816)

Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
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 @@ def test_shared_cache_deprecated(self):
                 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;