Skip to content

Commit 7d0a47e

Browse files
author
Erlend Egeberg Aasland
authored
bpo-44087: Disallow instantiation of sqlite3.Statement (GH-26567)
1 parent 185ecdc commit 7d0a47e

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Lib/sqlite3/test/dbapi.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import threading
2727
import unittest
2828

29+
from test.support import check_disallow_instantiation
2930
from test.support.os_helper import TESTFN, unlink
3031
from test.support import threading_helper
3132

@@ -105,6 +106,10 @@ def test_shared_cache_deprecated(self):
105106
sqlite.enable_shared_cache(enable)
106107
self.assertIn("dbapi.py", cm.filename)
107108

109+
def test_disallow_instantiation(self):
110+
cx = sqlite.connect(":memory:")
111+
check_disallow_instantiation(self, type(cx("select 1")))
112+
108113

109114
class ConnectionTests(unittest.TestCase):
110115

Modules/_sqlite/statement.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ static PyType_Spec stmt_spec = {
503503
.name = MODULE_NAME ".Statement",
504504
.basicsize = sizeof(pysqlite_Statement),
505505
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
506-
Py_TPFLAGS_IMMUTABLETYPE),
506+
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_DISALLOW_INSTANTIATION),
507507
.slots = stmt_slots,
508508
};
509509

0 commit comments

Comments
 (0)