]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] Add warnings filter suggestions to PEP 765 entry in What's New (GH-139658...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 6 Oct 2025 21:30:00 +0000 (23:30 +0200)
committerGitHub <noreply@github.com>
Mon, 6 Oct 2025 21:30:00 +0000 (00:30 +0300)
Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Doc/whatsnew/3.14.rst

index 9b7be2847ab6dd5745817e734674ee2818076b9a..00314cd49a668c743fe186f834cc18065db3822f 100644 (file)
@@ -937,6 +937,19 @@ The compiler now emits a :exc:`SyntaxWarning` when a :keyword:`return`,
 leaving a :keyword:`finally` block.
 This change is specified in :pep:`765`.
 
+In situations where this change is inconvenient (such as those where the
+warnings are redundant due to code linting), the :ref:`warning filter
+<warning-filter>` can be used to turn off all syntax warnings by adding
+``ignore::SyntaxWarning`` as a filter. This can be specified in combination
+with a filter that converts other warnings to errors (for example, passing
+``-Werror -Wignore::SyntaxWarning`` as CLI options, or setting
+``PYTHONWARNINGS=error,ignore::SyntaxWarning``).
+
+Note that applying such a filter at runtime using the :mod:`warnings` module
+will only suppress the warning in code that is compiled *after* the filter is
+adjusted. Code that is compiled prior to the filter adjustment (for example,
+when a module is imported) will still emit the syntax warning.
+
 (Contributed by Irit Katriel in :gh:`130080`.)