mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
gh-111726: Remove some doctests from sqlite3 docs (#117623)
* remove load extension doctest since we cannot skip it conditionally * remove sys.unraisablehook example; using unraisable hooks is not "an improved debug experience"
This commit is contained in:
parent
e1eeb990bd
commit
e338e1a4ec
1 changed files with 7 additions and 36 deletions
|
@ -394,29 +394,11 @@ Module functions
|
||||||
will get tracebacks from callbacks on :data:`sys.stderr`. Use ``False``
|
will get tracebacks from callbacks on :data:`sys.stderr`. Use ``False``
|
||||||
to disable the feature again.
|
to disable the feature again.
|
||||||
|
|
||||||
Register an :func:`unraisable hook handler <sys.unraisablehook>` for an
|
.. note::
|
||||||
improved debug experience:
|
|
||||||
|
|
||||||
.. testsetup:: sqlite3.trace
|
Errors in user-defined function callbacks are logged as unraisable exceptions.
|
||||||
|
Use an :func:`unraisable hook handler <sys.unraisablehook>` for
|
||||||
import sqlite3
|
introspection of the failed callback.
|
||||||
|
|
||||||
.. doctest:: sqlite3.trace
|
|
||||||
|
|
||||||
>>> sqlite3.enable_callback_tracebacks(True)
|
|
||||||
>>> con = sqlite3.connect(":memory:")
|
|
||||||
>>> def evil_trace(stmt):
|
|
||||||
... 5/0
|
|
||||||
...
|
|
||||||
>>> con.set_trace_callback(evil_trace)
|
|
||||||
>>> def debug(unraisable):
|
|
||||||
... print(f"{unraisable.exc_value!r} in callback {unraisable.object.__name__}")
|
|
||||||
... print(f"Error message: {unraisable.err_msg}")
|
|
||||||
>>> import sys
|
|
||||||
>>> sys.unraisablehook = debug
|
|
||||||
>>> cur = con.execute("SELECT 1")
|
|
||||||
ZeroDivisionError('division by zero') in callback evil_trace
|
|
||||||
Error message: None
|
|
||||||
|
|
||||||
.. function:: register_adapter(type, adapter, /)
|
.. function:: register_adapter(type, adapter, /)
|
||||||
|
|
||||||
|
@ -1068,13 +1050,10 @@ Connection objects
|
||||||
.. versionchanged:: 3.10
|
.. versionchanged:: 3.10
|
||||||
Added the ``sqlite3.enable_load_extension`` auditing event.
|
Added the ``sqlite3.enable_load_extension`` auditing event.
|
||||||
|
|
||||||
.. testsetup:: sqlite3.loadext
|
.. We cannot doctest the load extension API, since there is no convenient
|
||||||
|
way to skip it.
|
||||||
|
|
||||||
import sqlite3
|
.. code-block::
|
||||||
con = sqlite3.connect(":memory:")
|
|
||||||
|
|
||||||
.. testcode:: sqlite3.loadext
|
|
||||||
:skipif: True # not testable at the moment
|
|
||||||
|
|
||||||
con.enable_load_extension(True)
|
con.enable_load_extension(True)
|
||||||
|
|
||||||
|
@ -1098,14 +1077,6 @@ Connection objects
|
||||||
for row in con.execute("SELECT rowid, name, ingredients FROM recipe WHERE name MATCH 'pie'"):
|
for row in con.execute("SELECT rowid, name, ingredients FROM recipe WHERE name MATCH 'pie'"):
|
||||||
print(row)
|
print(row)
|
||||||
|
|
||||||
con.close()
|
|
||||||
|
|
||||||
.. testoutput:: sqlite3.loadext
|
|
||||||
:hide:
|
|
||||||
|
|
||||||
(2, 'broccoli pie', 'broccoli cheese onions flour')
|
|
||||||
(3, 'pumpkin pie', 'pumpkin sugar flour butter')
|
|
||||||
|
|
||||||
.. method:: load_extension(path, /, *, entrypoint=None)
|
.. method:: load_extension(path, /, *, entrypoint=None)
|
||||||
|
|
||||||
Load an SQLite extension from a shared library.
|
Load an SQLite extension from a shared library.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue