[Backport maintenance/4.0.x] Suppress SyntaxWarnings for Python 3.14 when parsing modules (#2854)
Suppress SyntaxWarnings for Python 3.14 when parsing modules (#2853)
(cherry picked from commit 8c4da6a361dea8d8a659e776af41d8b90c30a4a8)
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
diff --git a/ChangeLog b/ChangeLog
index 3e4af6e..3d3af5e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -14,6 +14,9 @@
Release date: TBA
+* Suppress ``SyntaxWarning`` for invalid escape sequences and return in finally on
+ Python 3.14 when parsing modules.
+
What's New in astroid 4.0.0?
============================
diff --git a/astroid/builder.py b/astroid/builder.py
index a107fed..b2b723c 100644
--- a/astroid/builder.py
+++ b/astroid/builder.py
@@ -23,7 +23,7 @@
from astroid import bases, modutils, nodes, raw_building, rebuilder, util
from astroid._ast import ParserModule, get_parser_module
-from astroid.const import PY312_PLUS
+from astroid.const import PY312_PLUS, PY314_PLUS
from astroid.exceptions import AstroidBuildingError, AstroidSyntaxError, InferenceError
if TYPE_CHECKING:
@@ -39,7 +39,11 @@
_STATEMENT_SELECTOR = "#@"
if PY312_PLUS:
- warnings.filterwarnings("ignore", "invalid escape sequence", SyntaxWarning)
+ warnings.filterwarnings("ignore", ".*invalid escape sequence", SyntaxWarning)
+if PY314_PLUS:
+ warnings.filterwarnings(
+ "ignore", "'(return|continue|break)' in a 'finally'", SyntaxWarning
+ )
def open_source_file(filename: str) -> tuple[TextIOWrapper, str, str]: