mirror of
https://github.com/python/cpython.git
synced 2025-11-02 22:51:25 +00:00
gh-133595: Clean up sqlite3.Connection APIs (GH-133605)
* All parameters of sqlite3.connect() except "database" are now keyword-only. * The first three parameters of methods create_function() and create_aggregate() are now positional-only. * The first parameter of methods set_authorizer(), set_progress_handler() and set_trace_callback() is now positional-only.
This commit is contained in:
parent
2561e148ec
commit
dcf93c4c93
17 changed files with 117 additions and 445 deletions
|
|
@ -422,27 +422,9 @@ def test_func_return_illegal_value(self):
|
|||
self.con.execute, "select badreturn()")
|
||||
|
||||
def test_func_keyword_args(self):
|
||||
regex = (
|
||||
r"Passing keyword arguments 'name', 'narg' and 'func' to "
|
||||
r"_sqlite3.Connection.create_function\(\) is deprecated. "
|
||||
r"Parameters 'name', 'narg' and 'func' will become "
|
||||
r"positional-only in Python 3.15."
|
||||
)
|
||||
|
||||
def noop():
|
||||
return None
|
||||
|
||||
with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
|
||||
self.con.create_function("noop", 0, func=noop)
|
||||
self.assertEqual(cm.filename, __file__)
|
||||
|
||||
with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
|
||||
self.con.create_function("noop", narg=0, func=noop)
|
||||
self.assertEqual(cm.filename, __file__)
|
||||
|
||||
with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
|
||||
self.con.create_function(name="noop", narg=0, func=noop)
|
||||
self.assertEqual(cm.filename, __file__)
|
||||
with self.assertRaisesRegex(TypeError,
|
||||
'takes exactly 3 positional arguments'):
|
||||
self.con.create_function("noop", 0, func=lambda: None)
|
||||
|
||||
|
||||
class WindowSumInt:
|
||||
|
|
@ -737,25 +719,9 @@ def test_aggr_text(self):
|
|||
self.assertEqual(val, txt)
|
||||
|
||||
def test_agg_keyword_args(self):
|
||||
regex = (
|
||||
r"Passing keyword arguments 'name', 'n_arg' and 'aggregate_class' to "
|
||||
r"_sqlite3.Connection.create_aggregate\(\) is deprecated. "
|
||||
r"Parameters 'name', 'n_arg' and 'aggregate_class' will become "
|
||||
r"positional-only in Python 3.15."
|
||||
)
|
||||
|
||||
with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
|
||||
with self.assertRaisesRegex(TypeError,
|
||||
'takes exactly 3 positional arguments'):
|
||||
self.con.create_aggregate("test", 1, aggregate_class=AggrText)
|
||||
self.assertEqual(cm.filename, __file__)
|
||||
|
||||
with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
|
||||
self.con.create_aggregate("test", n_arg=1, aggregate_class=AggrText)
|
||||
self.assertEqual(cm.filename, __file__)
|
||||
|
||||
with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
|
||||
self.con.create_aggregate(name="test", n_arg=0,
|
||||
aggregate_class=AggrText)
|
||||
self.assertEqual(cm.filename, __file__)
|
||||
|
||||
|
||||
class AuthorizerTests(unittest.TestCase):
|
||||
|
|
@ -800,16 +766,9 @@ def test_clear_authorizer(self):
|
|||
self.con.execute("select c2 from t1")
|
||||
|
||||
def test_authorizer_keyword_args(self):
|
||||
regex = (
|
||||
r"Passing keyword argument 'authorizer_callback' to "
|
||||
r"_sqlite3.Connection.set_authorizer\(\) is deprecated. "
|
||||
r"Parameter 'authorizer_callback' will become positional-only in "
|
||||
r"Python 3.15."
|
||||
)
|
||||
|
||||
with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
|
||||
with self.assertRaisesRegex(TypeError,
|
||||
'takes exactly 1 positional argument'):
|
||||
self.con.set_authorizer(authorizer_callback=lambda: None)
|
||||
self.assertEqual(cm.filename, __file__)
|
||||
|
||||
|
||||
class AuthorizerRaiseExceptionTests(AuthorizerTests):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue