Skip to content

Commit dcf93c4

Browse files
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.
1 parent 2561e14 commit dcf93c4

17 files changed

+117
-445
lines changed

Doc/library/sqlite3.rst

+21-31
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,10 @@ Reference
259259
Module functions
260260
^^^^^^^^^^^^^^^^
261261

262-
.. function:: connect(database, timeout=5.0, detect_types=0, \
262+
.. function:: connect(database, *, timeout=5.0, detect_types=0, \
263263
isolation_level="DEFERRED", check_same_thread=True, \
264264
factory=sqlite3.Connection, cached_statements=128, \
265-
uri=False, *, \
265+
uri=False, \
266266
autocommit=sqlite3.LEGACY_TRANSACTION_CONTROL)
267267

268268
Open a connection to an SQLite database.
@@ -355,11 +355,8 @@ Module functions
355355
.. versionchanged:: 3.12
356356
Added the *autocommit* parameter.
357357

358-
.. versionchanged:: 3.13
359-
Positional use of the parameters *timeout*, *detect_types*,
360-
*isolation_level*, *check_same_thread*, *factory*, *cached_statements*,
361-
and *uri* is deprecated.
362-
They will become keyword-only parameters in Python 3.15.
358+
.. versionchanged:: 3.15
359+
All parameters except *database* are now keyword-only.
363360

364361
.. function:: complete_statement(statement)
365362

@@ -693,7 +690,7 @@ Connection objects
693690
:meth:`~Cursor.executescript` on it with the given *sql_script*.
694691
Return the new cursor object.
695692

696-
.. method:: create_function(name, narg, func, *, deterministic=False)
693+
.. method:: create_function(name, narg, func, /, *, deterministic=False)
697694

698695
Create or remove a user-defined SQL function.
699696

@@ -719,6 +716,9 @@ Connection objects
719716
.. versionchanged:: 3.8
720717
Added the *deterministic* parameter.
721718

719+
.. versionchanged:: 3.15
720+
The first three parameters are now positional-only.
721+
722722
Example:
723723

724724
.. doctest::
@@ -733,13 +733,8 @@ Connection objects
733733
('acbd18db4cc2f85cedef654fccc4a4d8',)
734734
>>> con.close()
735735

736-
.. versionchanged:: 3.13
737-
738-
Passing *name*, *narg*, and *func* as keyword arguments is deprecated.
739-
These parameters will become positional-only in Python 3.15.
740-
741736

742-
.. method:: create_aggregate(name, n_arg, aggregate_class)
737+
.. method:: create_aggregate(name, n_arg, aggregate_class, /)
743738

744739
Create or remove a user-defined SQL aggregate function.
745740

@@ -763,6 +758,9 @@ Connection objects
763758
Set to ``None`` to remove an existing SQL aggregate function.
764759
:type aggregate_class: :term:`class` | None
765760

761+
.. versionchanged:: 3.15
762+
All three parameters are now positional-only.
763+
766764
Example:
767765

768766
.. testcode::
@@ -792,11 +790,6 @@ Connection objects
792790

793791
3
794792

795-
.. versionchanged:: 3.13
796-
797-
Passing *name*, *n_arg*, and *aggregate_class* as keyword arguments is deprecated.
798-
These parameters will become positional-only in Python 3.15.
799-
800793

801794
.. method:: create_window_function(name, num_params, aggregate_class, /)
802795

@@ -937,7 +930,7 @@ Connection objects
937930
Aborted queries will raise an :exc:`OperationalError`.
938931

939932

940-
.. method:: set_authorizer(authorizer_callback)
933+
.. method:: set_authorizer(authorizer_callback, /)
941934

942935
Register :term:`callable` *authorizer_callback* to be invoked
943936
for each attempt to access a column of a table in the database.
@@ -962,12 +955,11 @@ Connection objects
962955
.. versionchanged:: 3.11
963956
Added support for disabling the authorizer using ``None``.
964957

965-
.. versionchanged:: 3.13
966-
Passing *authorizer_callback* as a keyword argument is deprecated.
967-
The parameter will become positional-only in Python 3.15.
958+
.. versionchanged:: 3.15
959+
The only parameter is now positional-only.
968960

969961

970-
.. method:: set_progress_handler(progress_handler, n)
962+
.. method:: set_progress_handler(progress_handler, /, n)
971963

972964
Register :term:`callable` *progress_handler* to be invoked for every *n*
973965
instructions of the SQLite virtual machine. This is useful if you want to
@@ -981,12 +973,11 @@ Connection objects
981973
currently executing query and cause it to raise a :exc:`DatabaseError`
982974
exception.
983975

984-
.. versionchanged:: 3.13
985-
Passing *progress_handler* as a keyword argument is deprecated.
986-
The parameter will become positional-only in Python 3.15.
976+
.. versionchanged:: 3.15
977+
The first parameter is now positional-only.
987978

988979

989-
.. method:: set_trace_callback(trace_callback)
980+
.. method:: set_trace_callback(trace_callback, /)
990981

991982
Register :term:`callable` *trace_callback* to be invoked
992983
for each SQL statement that is actually executed by the SQLite backend.
@@ -1009,9 +1000,8 @@ Connection objects
10091000

10101001
.. versionadded:: 3.3
10111002

1012-
.. versionchanged:: 3.13
1013-
Passing *trace_callback* as a keyword argument is deprecated.
1014-
The parameter will become positional-only in Python 3.15.
1003+
.. versionchanged:: 3.15
1004+
The first parameter is now positional-only.
10151005

10161006

10171007
.. method:: enable_load_extension(enabled, /)

Doc/whatsnew/3.15.rst

+10-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,16 @@ New features
143143
Porting to Python 3.15
144144
----------------------
145145

146-
* TODO
146+
* :class:`sqlite3.Connection` APIs has been cleaned up.
147+
148+
* All parameters of :func:`sqlite3.connect` except *database* are now keyword-only.
149+
* The first three parameters of methods :meth:`~sqlite3.Connection.create_function`
150+
and :meth:`~sqlite3.Connection.create_aggregate` are now positional-only.
151+
* The first parameter of methods :meth:`~sqlite3.Connection.set_authorizer`,
152+
:meth:`~sqlite3.Connection.set_progress_handler` and
153+
:meth:`~sqlite3.Connection.set_trace_callback` is now positional-only.
154+
155+
(Contributed by Serhiy Storchaka in :gh:`133595`.)
147156

148157
Deprecated C APIs
149158
-----------------

Include/internal/pycore_global_objects_fini_generated.h

-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

-6
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ struct _Py_global_strings {
283283
STRUCT_FOR_ID(add_done_callback)
284284
STRUCT_FOR_ID(after_in_child)
285285
STRUCT_FOR_ID(after_in_parent)
286-
STRUCT_FOR_ID(aggregate_class)
287286
STRUCT_FOR_ID(alias)
288287
STRUCT_FOR_ID(align)
289288
STRUCT_FOR_ID(all)
@@ -300,7 +299,6 @@ struct _Py_global_strings {
300299
STRUCT_FOR_ID(ast)
301300
STRUCT_FOR_ID(athrow)
302301
STRUCT_FOR_ID(attribute)
303-
STRUCT_FOR_ID(authorizer_callback)
304302
STRUCT_FOR_ID(autocommit)
305303
STRUCT_FOR_ID(backtick)
306304
STRUCT_FOR_ID(base)
@@ -599,15 +597,13 @@ struct _Py_global_strings {
599597
STRUCT_FOR_ID(msg)
600598
STRUCT_FOR_ID(mutex)
601599
STRUCT_FOR_ID(mycmp)
602-
STRUCT_FOR_ID(n_arg)
603600
STRUCT_FOR_ID(n_fields)
604601
STRUCT_FOR_ID(n_sequence_fields)
605602
STRUCT_FOR_ID(n_unnamed_fields)
606603
STRUCT_FOR_ID(name)
607604
STRUCT_FOR_ID(name_from)
608605
STRUCT_FOR_ID(namespace_separator)
609606
STRUCT_FOR_ID(namespaces)
610-
STRUCT_FOR_ID(narg)
611607
STRUCT_FOR_ID(ndigits)
612608
STRUCT_FOR_ID(nested)
613609
STRUCT_FOR_ID(new_file_name)
@@ -665,7 +661,6 @@ struct _Py_global_strings {
665661
STRUCT_FOR_ID(print_file_and_line)
666662
STRUCT_FOR_ID(priority)
667663
STRUCT_FOR_ID(progress)
668-
STRUCT_FOR_ID(progress_handler)
669664
STRUCT_FOR_ID(progress_routine)
670665
STRUCT_FOR_ID(proto)
671666
STRUCT_FOR_ID(protocol)
@@ -771,7 +766,6 @@ struct _Py_global_strings {
771766
STRUCT_FOR_ID(timetuple)
772767
STRUCT_FOR_ID(timeunit)
773768
STRUCT_FOR_ID(top)
774-
STRUCT_FOR_ID(trace_callback)
775769
STRUCT_FOR_ID(traceback)
776770
STRUCT_FOR_ID(trailers)
777771
STRUCT_FOR_ID(translate)

Include/internal/pycore_runtime_init_generated.h

-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_unicodeobject_generated.h

-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/test_sqlite3/test_dbapi.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -550,17 +550,9 @@ def test_connection_config(self):
550550
cx.execute("insert into u values(0)")
551551

552552
def test_connect_positional_arguments(self):
553-
regex = (
554-
r"Passing more than 1 positional argument to sqlite3.connect\(\)"
555-
" is deprecated. Parameters 'timeout', 'detect_types', "
556-
"'isolation_level', 'check_same_thread', 'factory', "
557-
"'cached_statements' and 'uri' will become keyword-only "
558-
"parameters in Python 3.15."
559-
)
560-
with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
561-
cx = sqlite.connect(":memory:", 1.0)
562-
cx.close()
563-
self.assertEqual(cm.filename, __file__)
553+
with self.assertRaisesRegex(TypeError,
554+
r'connect\(\) takes at most 1 positional arguments'):
555+
sqlite.connect(":memory:", 1.0)
564556

565557
def test_connection_resource_warning(self):
566558
with self.assertWarns(ResourceWarning):

0 commit comments

Comments
 (0)