Skip to content

Commit 48a40fa

Browse files
ncoghlaniritkatrielAA-Turner
authored andcommitted
Add warnings filter suggestions to PEP 765 entry in What's New (python#139658)
Co-authored-by: Irit Katriel <[email protected]> Co-authored-by: Adam Turner <[email protected]>
1 parent c077713 commit 48a40fa

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Doc/whatsnew/3.14.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,19 @@ The compiler now emits a :exc:`SyntaxWarning` when a :keyword:`return`,
937937
leaving a :keyword:`finally` block.
938938
This change is specified in :pep:`765`.
939939

940+
In situations where this change is inconvenient (such as those where the
941+
warnings are redundant due to code linting), the :ref:`warning filter
942+
<warning-filter>` can be used to turn off all syntax warnings by adding
943+
``ignore::SyntaxWarning`` as a filter. This can be specified in combination
944+
with a filter that converts other warnings to errors (for example, passing
945+
``-Werror -Wignore::SyntaxWarning`` as CLI options, or setting
946+
``PYTHONWARNINGS=error,ignore::SyntaxWarning``).
947+
948+
Note that applying such a filter at runtime using the :mod:`warnings` module
949+
will only suppress the warning in code that is compiled *after* the filter is
950+
adjusted. Code that is compiled prior to the filter adjustment (for example,
951+
when a module is imported) will still emit the syntax warning.
952+
940953
(Contributed by Irit Katriel in :gh:`130080`.)
941954

942955

0 commit comments

Comments
 (0)