Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb99f398

Browse files
gh-61162: Clarify sqlite3 connection context manager docs (GH-93890)
Explicitly note that transactions are only closed if there is an opentransation at `__exit__`, and that transactions are not implicitlyopened during `__enter__`.Co-authored-by: CAM Gerlach <CAM.Gerlach@Gerlach.CAM>Co-authored-by: Stanley <46876382+slateny@users.noreply.github.com>Automerge-Triggered-By: GH:erlend-aasland(cherry picked from commit8e08978)Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@protonmail.com>
1 parent05f3367 commitb99f398

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

‎Doc/library/sqlite3.rst‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,13 +1420,27 @@ case-insensitively by name:
14201420
..literalinclude::../includes/sqlite3/rowclass.py
14211421

14221422

1423+
.. _sqlite3-connection-context-manager:
1424+
14231425
Using the connection as a context manager
14241426
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14251427

1426-
Connection objects can be used as context managers
1427-
that automatically commit or rollback transactions. In the event of an
1428-
exception, the transaction is rolled back; otherwise, the transaction is
1429-
committed:
1428+
A:class:`Connection` object can be used as a context manager that
1429+
automatically commits or rolls back open transactions when leaving the body of
1430+
the context manager.
1431+
If the body of the:keyword:`with` statement finishes without exceptions,
1432+
the transaction is committed.
1433+
If this commit fails,
1434+
or if the body of the ``with`` statement raises an uncaught exception,
1435+
the transaction is rolled back.
1436+
1437+
If there is no open transaction upon leaving the body of the ``with`` statement,
1438+
the context manager is a no-op.
1439+
1440+
..note::
1441+
1442+
The context manager neither implicitly opens a new transaction
1443+
nor closes the connection.
14301444

14311445
..literalinclude::../includes/sqlite3/ctx_manager.py
14321446

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Clarify:mod:`sqlite3` behavior when:ref:`sqlite3-connection-context-manager`.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp