8000 gh-93343: Expand warning filter examples · daniel-shimon/cpython@b0d41e8 · GitHub
[go: up one dir, main page]

Skip to content

Commit b0d41e8

Browse files
committed
pythongh-93343: Expand warning filter examples
Add examples of warning filters and the difference between programatic and environmental filters.
1 parent d3af83b commit b0d41e8

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Doc/library/warnings.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,18 @@ Some examples::
214214
ignore,default:::mymodule # Only report warnings triggered by "mymodule"
215215
error:::mymodule # Convert warnings to errors in "mymodule"
216216

217+
Note that :func:`filterwarnings` filters can use regex while :option:`-W` and :envvar:`PYTHONWARNINGS` cannot::
218+
219+
filterwarnings("ignore", message=".*generic", module=r"yourmodule\.submodule")
220+
# Ignore warnings in "yourmodule.submodule" which contain "generic"
221+
filterwarnings("ignore", module="yourmodule.*")
222+
# Ignore all warnings in "yourmodule" and its submodules
223+
224+
-W "ignore:generic::yourmodule.submodule:"
225+
# Ignore warnings in "yourmodule.submodule" which START with "generic"
226+
# Also note that the '.' in the module does not need to be escaped
227+
-W "ignore:::yourmodule:"
228+
# Ignore all warnings in "yourmodule", but NOT in its submodules
217229

218230
.. _default-warning-filter:
219231

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add examples of warning filters and the difference between programatic and
2+
environmental filters.

0 commit comments

Comments
 (0)
0