summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorErlend Egeberg Aasland <erlend.aasland@innova.no>2022-07-23 07:51:28 (GMT)
committerGitHub <noreply@github.com>2022-07-23 07:51:28 (GMT)
commita3d4d15f53777662ce0957500e5a538ce7161f5e (patch)
tree6471f47ed54d5df11e90342e6a1fff2fa7bad5a4 /Lib
parentc1e929858ad96fc6e41bc637e5ec9343b4f7e3c7 (diff)
downloadcpython-a3d4d15f53777662ce0957500e5a538ce7161f5e.zip
cpython-a3d4d15f53777662ce0957500e5a538ce7161f5e.tar.gz
cpython-a3d4d15f53777662ce0957500e5a538ce7161f5e.tar.bz2
gh-95132: Correctly relay *args and **kwds from sqlite3.connect to factory (#95146)
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>
Diffstat (limited to 'Lib')
-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 71603fa..7fdc45a 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):