Skip to content

Commit 2af7588

Browse files
authored
Add with warnings.catch_warnings() example to API docs (#670)
The new section explains how to suppress warning for only parts as opposed to for the entire program. The former is the preferred method.
1 parent 3bdd5c5 commit 2af7588

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

docs/source/api.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,13 +1405,35 @@ Filter Warnings
14051405
14061406
This example shows how to suppress the :class:`neo4j.ExperimentalWarning` using the :func:`python:warnings.filterwarnings` function.
14071407
1408+
.. code-block:: python
1409+
1410+
import warnings
1411+
from neo4j import ExperimentalWarning
1412+
1413+
...
1414+
1415+
with warnings.catch_warnings():
1416+
warnings.filterwarnings("ignore", category=ExperimentalWarning)
1417+
... # the call emitting the ExperimentalWarning
1418+
1419+
...
1420+
1421+
This will only mute the :class:`neo4j.ExperimentalWarning` for everything inside
1422+
the ``with``-block. This is the preferred way to mute warnings, as warnings
1423+
triggerd by new code will still be visible.
1424+
1425+
However, should you want to mute it for the entire application, use the
1426+
following code:
1427+
14081428
.. code-block:: python
14091429
14101430
import warnings
14111431
from neo4j import ExperimentalWarning
14121432
14131433
warnings.filterwarnings("ignore", category=ExperimentalWarning)
14141434
1435+
...
1436+
14151437
14161438
*********
14171439
Bookmarks

docs/source/async_api.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Async API Documentation
1010
This means everything documented on this page might be removed or change
1111
its API at any time (including in patch releases).
1212

13+
(See :ref:`filter-warnings-ref`)
14+
1315
.. versionadded:: 5.0
1416

1517
******************

0 commit comments

Comments
 (0)