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

Commite43adf8

Browse files
committed
gh-93343: Expand warning filter examples
Add examples of warning filters and the difference between programatic and environmental filters.
1 parentd3af83b commite43adf8

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

‎Doc/library/warnings.rst

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

217+
.. _warning-filter-examples:
218+
219+
Warning Filter Examples
220+
~~~~~~~~~~~~~~~~~~~~~~~
221+
222+
Here are some complex examples for filtering warnings.
223+
224+
Note that:func:`filterwarnings` filters have subtle differences
225+
from:option:`-W` and:envvar:`PYTHONWARNINGS` regarding the *message* and *module*
226+
parts of the filter (as described in:ref:`warning-filter`).
227+
228+
::
229+
230+
filterwarnings("ignore", message=".*generic", module=r"yourmodule\.submodule")
231+
# Ignore warnings in "yourmodule.submodule" which contain "generic"
232+
filterwarnings("ignore", message="generic", module=r"yourmodule\.submodule")
233+
# Ignore warnings in "yourmodule.submodule" which START with "generic"
234+
filterwarnings("ignore", module="yourmodule.*")
235+
# Ignore all warnings in "yourmodule" and its submodules
236+
237+
-W "ignore:generic::yourmodule.submodule:"
238+
# Ignore warnings in "yourmodule.submodule" which START with "generic"
239+
# (but not those containing it).
240+
# Also note that the '.' in the module does not need to be escaped
241+
# since it is not a regex.
242+
-W "ignore:::yourmodule:"
243+
# Ignore all warnings in "yourmodule", but NOT in its submodules
244+
217245

218246
.. _default-warning-filter:
219247

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 programmatic and
2+
environmental filters.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp