From a537452aff78cfd05e02e28c7e1a2cd4920a972c Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Fri, 10 Oct 2025 22:00:09 +0200 Subject: [PATCH] Suppress SyntaxWarnings for Python 3.14 when parsing modules (#2853) (cherry picked from commit 8c4da6a361dea8d8a659e776af41d8b90c30a4a8) --- ChangeLog | 3 +++ astroid/builder.py | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3e4af6e9b..3d3af5ee9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,9 @@ What's New in astroid 4.0.1? 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 a107fed99..b2b723cda 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]: