Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/sqlite3/test/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import sqlite3 as sqlite
import sys

from test.support import check_disallow_instantiation
from test.support.os_helper import TESTFN, unlink


Expand Down Expand Up @@ -92,6 +93,10 @@ 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:")
check_disallow_instantiation(self, type(cx("select 1")))


class ConnectionTests(unittest.TestCase):

Expand Down
2 changes: 1 addition & 1 deletion Modules/_sqlite/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down