From 5435a8a9d928b96c5731774779684f41d57331da Mon Sep 17 00:00:00 2001 From: Alyssa Coghlan Date: Mon, 6 Oct 2025 23:34:58 +1000 Subject: [PATCH 1/3] PEP 765: What's New warnings filter suggestions For CI use cases where static code analysis is in use, emitting SyntaxWarnings is essentially redundant. Accordingly, there's no harm in suggesting that folks turn them off to avoid poor interactions between PEP 765 and treating warnings as errors. --- Doc/whatsnew/3.14.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index c226f57e5025f0..a144e5df5ca5d6 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -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`. +For use cases where this change is inconvenient (such as those where the +warnings are redundant due to code linting), syntax warnings specifically +may be switched off via the :ref:`warning filter `, using the +clause ``ignore::SyntaxWarning``. This can also 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 (rather than via the interpreter's +startup configuration) 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 warning. + (Contributed by Irit Katriel in :gh:`130080`.) From 9db5c40501a292dc2bcd06d0c1b7ef385a0f7bba Mon Sep 17 00:00:00 2001 From: Alyssa Coghlan Date: Tue, 7 Oct 2025 02:33:22 +1000 Subject: [PATCH 2/3] Apply suggestions from code review 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 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index a144e5df5ca5d6..58431f007ffa6a 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -937,18 +937,18 @@ The compiler now emits a :exc:`SyntaxWarning` when a :keyword:`return`, leaving a :keyword:`finally` block. This change is specified in :pep:`765`. -For use cases where this change is inconvenient (such as those where the -warnings are redundant due to code linting), syntax warnings specifically -may be switched off via the :ref:`warning filter `, using the -clause ``ignore::SyntaxWarning``. This can also be specified in combination +In situations where this change is inconvenient (such as those where the +warnings are redundant due to code linting), the :ref:`warning filter +` can be used to turn off all syntax warnings, by using the +``ignore::SyntaxWarning`` 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 (rather than via the interpreter's -startup configuration) 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 warning. +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`.) From 9b1ae088967f93fa25860907e717b0caf3b4c26f Mon Sep 17 00:00:00 2001 From: Alyssa Coghlan Date: Tue, 7 Oct 2025 02:35:39 +1000 Subject: [PATCH 3/3] Tweak code review suggestions --- Doc/whatsnew/3.14.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 58431f007ffa6a..15fab9c6b3e2e1 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -939,13 +939,13 @@ 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 -` can be used to turn off all syntax warnings, by using the -``ignore::SyntaxWarning`` filter. This can be specified in combination +` 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 +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.