[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 a3d4d15f53)

Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
This commit is contained in:
Erlend Egeberg Aasland 2022-07-23 10:23:19 +02:00 committed by GitHub
parent 064462a719
commit 5d3f2fbf37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 146 deletions

View file

@ -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):