summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_sqlite3/test_factory.py
diff options
context:
space:
mode:
authorErlend Egeberg Aasland <erlend.aasland@innova.no>2022-07-23 08:23:19 (GMT)
committerGitHub <noreply@github.com>2022-07-23 08:23:19 (GMT)
commit5d3f2fbf37cd8faa9830490ac244b051d3879990 (patch)
tree69353dadec115b0f1492148f1034b7deee895837 /Lib/test/test_sqlite3/test_factory.py
parent064462a719509c1382207387e3a3ef187f7b55bf (diff)
downloadcpython-5d3f2fbf37cd8faa9830490ac244b051d3879990.zip
cpython-5d3f2fbf37cd8faa9830490ac244b051d3879990.tar.gz
cpython-5d3f2fbf37cd8faa9830490ac244b051d3879990.tar.bz2
[3.11] gh-95132: Correctly relay *args and **kwds from sqlite3.connect to factory (GH-95146) (#95158)
This PR partially reverts gh-24421 (PR) and fixes the remaining concerns given in gh-93044 (issue): - keyword arguments are passed as positional arguments to factory() - if an argument is not passed to sqlite3.connect(), its default value is passed to factory() Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>. (cherry picked from commit a3d4d15f53777662ce0957500e5a538ce7161f5e) Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
Diffstat (limited to 'Lib/test/test_sqlite3/test_factory.py')
-rw-r--r--Lib/test/test_sqlite3/test_factory.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_sqlite3/test_factory.py b/Lib/test/test_sqlite3/test_factory.py
index 420855b..cdaf125 100644
--- a/Lib/test/test_sqlite3/test_factory.py
+++ b/Lib/test/test_sqlite3/test_factory.py
@@ -50,6 +50,26 @@ class ConnectionFactoryTests(unittest.TestCase):
con = sqlite.connect(":memory:", factory=factory)
self.assertIsInstance(con, factory)
+ def test_connection_factory_relayed_call(self):
+ # gh-95132: keyword args must not be passed as positional args
+ class Factory(sqlite.Connection):
+ def __init__(self, *args, **kwargs):
+ kwargs["isolation_level"] = None
+ super(Factory, self).__init__(*args, **kwargs)
+
+ con = sqlite.connect(":memory:", factory=Factory)
+ self.assertIsNone(con.isolation_level)
+ self.assertIsInstance(con, Factory)
+
+ def test_connection_factory_as_positional_arg(self):
+ class Factory(sqlite.Connection):
+ def __init__(self, *args, **kwargs):
+ super(Factory, self).__init__(*args, **kwargs)
+
+ con = sqlite.connect(":memory:", 5.0, 0, None, True, Factory)
+ self.assertIsNone(con.isolation_level)
+ self.assertIsInstance(con, Factory)
+
class CursorFactoryTests(unittest.TestCase):
def setUp(self):