Skip to content

Commit c11f9d2

Browse files
authored
Add with warnings.catch_warnings() example to API docs (#669)
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 2b9e9e6 commit c11f9d2

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/source/api.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,13 +1346,35 @@ Filter Warnings
13461346
13471347
This example shows how to suppress the :class:`neo4j.ExperimentalWarning` using the :func:`python:warnings.filterwarnings` function.
13481348
1349+
.. code-block:: python
1350+
1351+
import warnings
1352+
from neo4j import ExperimentalWarning
1353+
1354+
...
1355+
1356+
with warnings.catch_warnings():
1357+
warnings.filterwarnings("ignore", category=ExperimentalWarning)
1358+
... # the call emitting the ExperimentalWarning
1359+
1360+
...
1361+
1362+
This will only mute the :class:`neo4j.ExperimentalWarning` for everything inside
1363+
the ``with``-block. This is the preferred way to mute warnings, as warnings
1364+
triggerd by new code will still be visible.
1365+
1366+
However, should you want to mute it for the entire application, use the
1367+
following code:
1368+
13491369
.. code-block:: python
13501370
13511371
import warnings
13521372
from neo4j import ExperimentalWarning
13531373
13541374
warnings.filterwarnings("ignore", category=ExperimentalWarning)
13551375
1376+
...
1377+
13561378
13571379
********
13581380
Bookmark

0 commit comments

Comments
 (0)