summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/sqlite3/test/dbapi.py5
-rw-r--r--Modules/_sqlite/statement.c2
2 files changed, 6 insertions, 1 deletions
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;