Skip to content

Commit 12d92c7

Browse files
erlend-aaslandezio-melottiAlexWaygood
authored
pythongh-95273: Improve documented return values and exceptions raised for sqlite3 class methods (python#95530)
Co-authored-by: Ezio Melotti <[email protected]> Co-authored-by: Alex Waygood <[email protected]>
1 parent 6a5104f commit 12d92c7

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
@@ -295,15 +295,14 @@ Module functions and constants
295295
in RAM instead of on disk.
296296
:type database: :term:`path-like object`
297297

298-
:param timeout:
298+
:param float timeout:
299299
How many seconds the connection should wait before raising
300300
an exception, if the database is locked by another connection.
301301
If another connection opens a transaction to modify the database,
302302
it will be locked until that transaction is committed.
303303
Default five seconds.
304-
:type timeout: float
305304

306-
:param detect_types:
305+
:param int detect_types:
307306
Control whether and how data types not
308307
:ref:`natively supported by SQLite <sqlite3-types>`
309308
are looked up to be converted to Python types,
@@ -316,7 +315,6 @@ Module functions and constants
316315
even when the *detect_types* parameter is set; :class:`str` will be
317316
returned instead.
318317
By default (``0``), type detection is disabled.
319-
:type detect_types: int
320318

321319
:param isolation_level:
322320
The :attr:`~Connection.isolation_level` of the connection,
@@ -326,33 +324,29 @@ Module functions and constants
326324
See :ref:`sqlite3-controlling-transactions` for more.
327325
:type isolation_level: str | None
328326

329-
:param check_same_thread:
327+
:param bool check_same_thread:
330328
If ``True`` (default), only the creating thread may use the connection.
331329
If ``False``, the connection may be shared across multiple threads;
332330
if so, write operations should be serialized by the user to avoid data
333331
corruption.
334-
:type check_same_thread: bool
335332

336-
:param factory:
333+
:param Connection factory:
337334
A custom subclass of :class:`Connection` to create the connection with,
338335
if not the default :class:`Connection` class.
339-
:type factory: :class:`Connection`
340336

341-
:param cached_statements:
337+
:param int cached_statements:
342338
The number of statements that ``sqlite3``
343339
should internally cache for this connection, to avoid parsing overhead.
344340
By default, 128 statements.
345-
:type cached_statements: int
346341

347-
:param uri:
342+
:param bool uri:
348343
If set to ``True``, *database* is interpreted as a
349344
:abbr:`URI (Uniform Resource Identifier)` with a file path
350345
and an optional query string.
351346
The scheme part *must* be ``"file:"``,
352347
and the path can be relative or absolute.
353348
The query string allows passing parameters to SQLite,
354349
enabling various :ref:`sqlite3-uri-tricks`.
355-
:type uri: bool
356350

357351
:rtype: Connection
358352

@@ -487,28 +481,23 @@ Connection objects
487481
Open a :class:`Blob` handle to an existing
488482
:abbr:`BLOB (Binary Large OBject)`.
489483

490-
:param table:
484+
:param str table:
491485
The name of the table where the blob is located.
492-
:type table: str
493486

494-
:param column:
487+
:param str column:
495488
The name of the column where the blob is located.
496-
:type column: str
497489

498-
:param row:
490+
:param str row:
499491
The name of the row where the blob is located.
500-
:type row: str
501492

502-
:param readonly:
493+
:param bool readonly:
503494
Set to ``True`` if the blob should be opened without write
504495
permissions.
505496
Defaults to ``False``.
506-
:type readonly: bool
507497

508-
:param name:
498+
:param str name:
509499
The name of the database where the blob is located.
510500
Defaults to ``"main"``.
511-
:type name: str
512501

513502
:raises OperationalError:
514503
When trying to open a blob in a ``WITHOUT ROWID`` table.
@@ -561,14 +550,12 @@ Connection objects
561550

562551
Create or remove a user-defined SQL function.
563552

564-
:param name:
553+
:param str name:
565554
The name of the SQL function.
566-
:type name: str
567555

568-
:param narg:
556+
:param int narg:
569557
The number of arguments the SQL function can accept.
570558
If ``-1``, it may take any number of arguments.
571-
:type narg: int
572559

573560
:param func:
574561
A callable that is called when the SQL function is invoked.
@@ -577,11 +564,10 @@ Connection objects
577564
Set to ``None`` to remove an existing SQL function.
578565
:type func: :term:`callback` | None
579566

580-
:param deterministic:
567+
:param bool deterministic:
581568
If ``True``, the created SQL function is marked as
582569
`deterministic <https://sqlite.org/deterministic.html>`_,
583570
which allows SQLite to perform additional optimizations.
584-
:type deterministic: bool
585571

586572
:raises NotSupportedError:
587573
If *deterministic* is used with SQLite versions older than 3.8.3.
@@ -598,14 +584,12 @@ Connection objects
598584

599585
Create or remove a user-defined SQL aggregate function.
600586

601-
:param name:
587+
:param str name:
602588
The name of the SQL aggregate function.
603-
:type name: str
604589

605-
:param n_arg:
590+
:param int n_arg:
606591
The number of arguments the SQL aggregate function can accept.
607592
If ``-1``, it may take any number of arguments.
608-
:type n_arg: int
609593

610594
:param aggregate_class:
611595
A class must implement the following methods:
@@ -629,14 +613,12 @@ Connection objects
629613

630614
Create or remove a user-defined aggregate window function.
631615

632-
:param name:
616+
:param str name:
633617
The name of the SQL aggregate window function to create or remove.
634-
:type name: str
635618

636-
:param num_params:
619+
:param int num_params:
637620
The number of arguments the SQL aggregate window function can accept.
638621
If ``-1``, it may take any number of arguments.
639-
:type num_params: int
640622

641623
:param aggregate_class:
642624
A class that must implement the following methods:
@@ -862,16 +844,14 @@ Connection objects
862844
Works even if the database is being accessed by other clients
863845
or concurrently by the same connection.
864846

865-
:param target:
847+
:param Connection target:
866848
The database connection to save the backup to.
867-
:type target: Connection
868849

869-
:param pages:
850+
:param int pages:
870851
The number of pages to copy at a time.
871852
If equal to or less than ``0``,
872853
the entire database is copied in a single step.
873854
Defaults to ``-1``.
874-
:type pages: int
875855

876856
:param progress:
877857
If set to a callable, it is invoked with three integer arguments for
@@ -882,18 +862,16 @@ Connection objects
882862
Defaults to ``None``.
883863
:type progress: :term:`callback` | None
884864
885-
:param name:
865+
:param str name:
886866
The name of the database to back up.
887867
Either ``"main"`` (the default) for the main database,
888868
``"temp"`` for the temporary database,
889869
or the name of a custom database as attached using the
890870
``ATTACH DATABASE`` SQL statement.
891-
:type name: str
892871

893-
:param sleep:
872+
:param float sleep:
894873
The number of seconds to sleep between successive attempts
895874
to back up remaining pages.
896-
:type sleep: float
897875

898876
Example 1, copy an existing database into another::
899877

@@ -919,11 +897,17 @@ Connection objects
919897

920898
.. versionadded:: 3.7
921899

922-
923900
.. method:: getlimit(category, /)
924901

925-
Get a connection runtime limit. *category* is the limit category to be
926-
queried.
902+
Get a connection runtime limit.
903+
904+
:param int category:
905+
The `SQLite limit category`_ to be queried.
906+
907+
:rtype: int
908+
909+
:raises ProgrammingError:
910+
If *category* is not recognised by the underlying SQLite library.
927911

928912
Example, query the maximum length of an SQL statement::
929913

@@ -937,14 +921,23 @@ Connection objects
937921

938922
.. method:: setlimit(category, limit, /)
939923

940-
Set a connection runtime limit. *category* is the limit category to be
941-
set. *limit* is the new limit. If the new limit is a negative number, the
942-
limit is unchanged.
943-
924+
Set a connection runtime limit.
944925
Attempts to increase a limit above its hard upper bound are silently
945926
truncated to the hard upper bound. Regardless of whether or not the limit
946927
was changed, the prior value of the limit is returned.
947928

929+
:param int category:
930+
The `SQLite limit category`_ to be set.
931+
932+
:param int limit:
933+
The value of the new limit.
934+
If negative, the current limit is unchanged.
935+
936+
:rtype: int
937+
938+
:raises ProgrammingError:
939+
If *category* is not recognised by the underlying SQLite library.
940+
948941
Example, limit the number of attached databases to 1::
949942

950943
import sqlite3
@@ -953,6 +946,8 @@ Connection objects
953946

954947
.. versionadded:: 3.11
955948

949+
.. _SQLite limit category: https://www.sqlite.org/c3ref/c_limit_attached.html
950+
956951

957952
.. method:: serialize(*, name="main")
958953

@@ -962,8 +957,11 @@ Connection objects
962957
serialization is the same sequence of bytes which would be written to
963958
disk if that database were backed up to disk.
964959

965-
*name* is the database to be serialized, and defaults to the main
966-
database.
960+
:param str name:
961+
The database name to be serialized.
962+
Defaults to ``"main"``.
963+
964+
:rtype: bytes
967965

968966
.. note::
969967

@@ -979,12 +977,24 @@ Connection objects
979977
:class:`Connection`.
980978
This method causes the database connection to disconnect from database
981979
*name*, and reopen *name* as an in-memory database based on the
982-
serialization contained in *data*. Deserialization will raise
983-
:exc:`OperationalError` if the database connection is currently involved
984-
in a read transaction or a backup operation. :exc:`OverflowError` will be
985-
raised if ``len(data)`` is larger than ``2**63 - 1``, and
986-
:exc:`DatabaseError` will be raised if *data* does not contain a valid
987-
SQLite database.
980+
serialization contained in *data*.
981+
982+
:param bytes data:
983+
A serialized database.
984+
985+
:param str name:
986+
The database name to deserialize into.
987+
Defaults to ``"main"``.
988+
989+
:raises OperationalError:
990+
If the database connection is currently involved in a read
991+
transaction or a backup operation.
992+
993+
:raises DatabaseError:
994+
If *data* does not contain a valid SQLite database.
995+
996+
:raises OverflowError:
997+
If :func:`len(data) <len>` is larger than ``2**63 - 1``.
988998

989999
.. note::
9901000

@@ -1081,13 +1091,13 @@ Cursor objects
10811091

10821092
.. method:: fetchone()
10831093

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

10871097

10881098
.. method:: fetchmany(size=cursor.arraysize)
10891099

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

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

11041114
.. method:: fetchall()
11051115

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

0 commit comments

Comments
 (0)