Skip to content

Commit c9986be

Browse files
[3.11] gh-95273: Improve documented return values and exceptions raised for sqlite3 class methods (GH-95530) (#95673)
Co-authored-by: Ezio Melotti <[email protected]> Co-authored-by: Alex Waygood <[email protected]> (cherry picked from commit 12d92c7) Co-authored-by: Erlend Egeberg Aasland <[email protected]>
1 parent 6d83441 commit c9986be

File tree

1 file changed

+72
-62
lines changed

1 file changed

+72
-62
lines changed

Doc/library/sqlite3.rst

+72-62
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,14 @@ Module functions and constants
285285
in RAM instead of on disk.
286286
:type database: :term:`path-like object`
287287

288-
:param timeout:
288+
:param float timeout:
289289
How many seconds the connection should wait before raising
290290
an exception, if the database is locked by another connection.
291291
If another connection opens a transaction to modify the database,
292292
it will be locked until that transaction is committed.
293293
Default five seconds.
294-
:type timeout: float
295294

296-
:param detect_types:
295+
:param int detect_types:
297296
Control whether and how data types not
298297
:ref:`natively supported by SQLite <sqlite3-types>`
299298
are looked up to be converted to Python types,
@@ -306,7 +305,6 @@ Module functions and constants
306305
even when the *detect_types* parameter is set; :class:`str` will be
307306
returned instead.
308307
By default (``0``), type detection is disabled.
309-
:type detect_types: int
310308

311309
:param isolation_level:
312310
The :attr:`~Connection.isolation_level` of the connection,
@@ -316,33 +314,29 @@ Module functions and constants
316314
See :ref:`sqlite3-controlling-transactions` for more.
317315
:type isolation_level: str | None
318316

319-
:param check_same_thread:
317+
:param bool check_same_thread:
320318
If ``True`` (default), only the creating thread may use the connection.
321319
If ``False``, the connection may be shared across multiple threads;
322320
if so, write operations should be serialized by the user to avoid data
323321
corruption.
324-
:type check_same_thread: bool
325322

326-
:param factory:
323+
:param Connection factory:
327324
A custom subclass of :class:`Connection` to create the connection with,
328325
if not the default :class:`Connection` class.
329-
:type factory: :class:`Connection`
330326

331-
:param cached_statements:
327+
:param int cached_statements:
332328
The number of statements that ``sqlite3``
333329
should internally cache for this connection, to avoid parsing overhead.
334330
By default, 128 statements.
335-
:type cached_statements: int
336331

337-
:param uri:
332+
:param bool uri:
338333
If set to ``True``, *database* is interpreted as a
339334
:abbr:`URI (Uniform Resource Identifier)` with a file path
340335
and an optional query string.
341336
The scheme part *must* be ``"file:"``,
342337
and the path can be relative or absolute.
343338
The query string allows passing parameters to SQLite,
344339
enabling various :ref:`sqlite3-uri-tricks`.
345-
:type uri: bool
346340

347341
:rtype: Connection
348342

@@ -477,28 +471,23 @@ Connection objects
477471
Open a :class:`Blob` handle to an existing
478472
:abbr:`BLOB (Binary Large OBject)`.
479473

480-
:param table:
474+
:param str table:
481475
The name of the table where the blob is located.
482-
:type table: str
483476

484-
:param column:
477+
:param str column:
485478
The name of the column where the blob is located.
486-
:type column: str
487479

488-
:param row:
480+
:param str row:
489481
The name of the row where the blob is located.
490-
:type row: str
491482

492-
:param readonly:
483+
:param bool readonly:
493484
Set to ``True`` if the blob should be opened without write
494485
permissions.
495486
Defaults to ``False``.
496-
:type readonly: bool
497487

498-
:param name:
488+
:param str name:
499489
The name of the database where the blob is located.
500490
Defaults to ``"main"``.
501-
:type name: str
502491

503492
:raises OperationalError:
504493
When trying to open a blob in a ``WITHOUT ROWID`` table.
@@ -551,14 +540,12 @@ Connection objects
551540

552541
Create or remove a user-defined SQL function.
553542

554-
:param name:
543+
:param str name:
555544
The name of the SQL function.
556-
:type name: str
557545

558-
:param narg:
546+
:param int narg:
559547
The number of arguments the SQL function can accept.
560548
If ``-1``, it may take any number of arguments.
561-
:type narg: int
562549

563550
:param func:
564551
A callable that is called when the SQL function is invoked.
@@ -567,11 +554,10 @@ Connection objects
567554
Set to ``None`` to remove an existing SQL function.
568555
:type func: :term:`callback` | None
569556

570-
:param deterministic:
557+
:param bool deterministic:
571558
If ``True``, the created SQL function is marked as
572559
`deterministic <https://sqlite.org/deterministic.html>`_,
573560
which allows SQLite to perform additional optimizations.
574-
:type deterministic: bool
575561

576562
:raises NotSupportedError:
577563
If *deterministic* is used with SQLite versions older than 3.8.3.
@@ -588,14 +574,12 @@ Connection objects
588574

589575
Create or remove a user-defined SQL aggregate function.
590576

591-
:param name:
577+
:param str name:
592578
The name of the SQL aggregate function.
593-
:type name: str
594579

595-
:param n_arg:
580+
:param int n_arg:
596581
The number of arguments the SQL aggregate function can accept.
597582
If ``-1``, it may take any number of arguments.
598-
:type n_arg: int
599583

600584
:param aggregate_class:
601585
A class must implement the following methods:
@@ -619,14 +603,12 @@ Connection objects
619603

620604
Create or remove a user-defined aggregate window function.
621605

622-
:param name:
606+
:param str name:
623607
The name of the SQL aggregate window function to create or remove.
624-
:type name: str
625608

626-
:param num_params:
609+
:param int num_params:
627610
The number of arguments the SQL aggregate window function can accept.
628611
If ``-1``, it may take any number of arguments.
629-
:type num_params: int
630612

631613
:param aggregate_class:
632614
A class that must implement the following methods:
@@ -852,16 +834,14 @@ Connection objects
852834
Works even if the database is being accessed by other clients
853835
or concurrently by the same connection.
854836

855-
:param target:
837+
:param Connection target:
856838
The database connection to save the backup to.
857-
:type target: Connection
858839

859-
:param pages:
840+
:param int pages:
860841
The number of pages to copy at a time.
861842
If equal to or less than ``0``,
862843
the entire database is copied in a single step.
863844
Defaults to ``-1``.
864-
:type pages: int
865845

866846
:param progress:
867847
If set to a callable, it is invoked with three integer arguments for
@@ -872,18 +852,16 @@ Connection objects
872852
Defaults to ``None``.
873853
:type progress: :term:`callback` | None
874854
875-
:param name:
855+
:param str name:
876856
The name of the database to back up.
877857
Either ``"main"`` (the default) for the main database,
878858
``"temp"`` for the temporary database,
879859
or the name of a custom database as attached using the
880860
``ATTACH DATABASE`` SQL statement.
881-
:type name: str
882861

883-
:param sleep:
862+
:param float sleep:
884863
The number of seconds to sleep between successive attempts
885864
to back up remaining pages.
886-
:type sleep: float
887865

888866
Example 1, copy an existing database into another::
889867

@@ -909,11 +887,17 @@ Connection objects
909887

910888
.. versionadded:: 3.7
911889

912-
913890
.. method:: getlimit(category, /)
914891

915-
Get a connection runtime limit. *category* is the limit category to be
916-
queried.
892+
Get a connection runtime limit.
893+
894+
:param int category:
895+
The `SQLite limit category`_ to be queried.
896+
897+
:rtype: int
898+
899+
:raises ProgrammingError:
900+
If *category* is not recognised by the underlying SQLite library.
917901

918902
Example, query the maximum length of an SQL statement::
919903

@@ -927,14 +911,23 @@ Connection objects
927911

928912
.. method:: setlimit(category, limit, /)
929913

930-
Set a connection runtime limit. *category* is the limit category to be
931-
set. *limit* is the new limit. If the new limit is a negative number, the
932-
limit is unchanged.
933-
914+
Set a connection runtime limit.
934915
Attempts to increase a limit above its hard upper bound are silently
935916
truncated to the hard upper bound. Regardless of whether or not the limit
936917
was changed, the prior value of the limit is returned.
937918

919+
:param int category:
920+
The `SQLite limit category`_ to be set.
921+
922+
:param int limit:
923+
The value of the new limit.
924+
If negative, the current limit is unchanged.
925+
926+
:rtype: int
927+
928+
:raises ProgrammingError:
929+
If *category* is not recognised by the underlying SQLite library.
930+
938931
Example, limit the number of attached databases to 1::
939932

940933
import sqlite3
@@ -943,6 +936,8 @@ Connection objects
943936

944937
.. versionadded:: 3.11
945938

939+
.. _SQLite limit category: https://www.sqlite.org/c3ref/c_limit_attached.html
940+
946941

947942
.. method:: serialize(*, name="main")
948943

@@ -952,8 +947,11 @@ Connection objects
952947
serialization is the same sequence of bytes which would be written to
953948
disk if that database were backed up to disk.
954949

955-
*name* is the database to be serialized, and defaults to the main
956-
database.
950+
:param str name:
951+
The database name to be serialized.
952+
Defaults to ``"main"``.
953+
954+
:rtype: bytes
957955

958956
.. note::
959957

@@ -969,12 +967,24 @@ Connection objects
969967
:class:`Connection`.
970968
This method causes the database connection to disconnect from database
971969
*name*, and reopen *name* as an in-memory database based on the
972-
serialization contained in *data*. Deserialization will raise
973-
:exc:`OperationalError` if the database connection is currently involved
974-
in a read transaction or a backup operation. :exc:`OverflowError` will be
975-
raised if ``len(data)`` is larger than ``2**63 - 1``, and
976-
:exc:`DatabaseError` will be raised if *data* does not contain a valid
977-
SQLite database.
970+
serialization contained in *data*.
971+
972+
:param bytes data:
973+
A serialized database.
974+
975+
:param str name:
976+
The database name to deserialize into.
977+
Defaults to ``"main"``.
978+
979+
:raises OperationalError:
980+
If the database connection is currently involved in a read
981+
transaction or a backup operation.
982+
983+
:raises DatabaseError:
984+
If *data* does not contain a valid SQLite database.
985+
986+
:raises OverflowError:
987+
If :func:`len(data) <len>` is larger than ``2**63 - 1``.
978988

979989
.. note::
980990

@@ -1071,13 +1081,13 @@ Cursor objects
10711081

10721082
.. method:: fetchone()
10731083

1074-
Fetch the next row of a query result set as a :class:`tuple`.
1084+
Return the next row of a query result set as a :class:`tuple`.
10751085
Return ``None`` if no more data is available.
10761086

10771087

10781088
.. method:: fetchmany(size=cursor.arraysize)
10791089

1080-
Fetch the next set of rows of a query result as a :class:`list`.
1090+
Return the next set of rows of a query result as a :class:`list`.
10811091
Return an empty list if no more rows are available.
10821092

10831093
The number of rows to fetch per call is specified by the *size* parameter.
@@ -1093,7 +1103,7 @@ Cursor objects
10931103

10941104
.. method:: fetchall()
10951105

1096-
Fetch all (remaining) rows of a query result as a :class:`list`.
1106+
Return all (remaining) rows of a query result as a :class:`list`.
10971107
Return an empty list if no rows are available.
10981108
Note that the :attr:`arraysize` attribute can affect the performance of
10991109
this operation.

0 commit comments

Comments
 (0)