Skip to content

Commit f16ae2d

Browse files
Clarify escaped dots in regexes
1 parent f3684a6 commit f16ae2d

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

Doc/library/warnings.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,23 +224,28 @@ Here are some complex examples for filtering warnings.
224224
Note that :func:`filterwarnings` filters have subtle differences
225225
from :option:`-W` and :envvar:`PYTHONWARNINGS` regarding the *message* and *module*
226226
parts of the filter (as described in :ref:`warning-filter`).
227+
Mainly, 'message' and 'module' are regular expressions in the former,
228+
but literal strings in the latter two.
227229

228230
::
229231

230232
filterwarnings("ignore", message=".*generic", module=r"yourmodule\.submodule")
231-
# Ignore warnings in "yourmodule.submodule" which contain "generic"
233+
# Ignore warnings in "yourmodule.submodule" which contain "generic".
234+
# Note that the '.' in 'message' marks any character and in 'module' it is escaped,
235+
# in order to match a literal dot character.
232236
filterwarnings("ignore", message="generic", module=r"yourmodule\.submodule")
233-
# Ignore warnings in "yourmodule.submodule" which START with "generic"
237+
# Ignore warnings in "yourmodule.submodule" which START with "generic".
234238
filterwarnings("ignore", module="yourmodule.*")
235-
# Ignore all warnings in "yourmodule" and its submodules
239+
# Ignore all warnings in "yourmodule" and its submodules.
240+
# Note that the '.' in 'module' marks any character so is not escaped.
236241

237242
-W "ignore:generic::yourmodule.submodule:"
238243
# Ignore warnings in "yourmodule.submodule" which START with "generic"
239244
# (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.
245+
# Also note that the '.' in the module part does not need to be escaped
246+
# since it is not a regular expression.
242247
-W "ignore:::yourmodule:"
243-
# Ignore all warnings in "yourmodule", but NOT in its submodules
248+
# Ignore all warnings in "yourmodule", but NOT in its submodules.
244249

245250

246251
.. _default-warning-filter:

0 commit comments

Comments
 (0)