From 911532a7306414853a5ca782b2ae915ab1154ade Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Fri, 10 Oct 2025 00:48:31 +0200 Subject: [PATCH] Suppress SyntaxWarnings for Python 3.14 when parsing modules --- ChangeLog | 3 +++ astroid/builder.py | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 08b9605c7..426a9b62b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -21,6 +21,9 @@ Release date: TBA * Make `type.__new__()` raise clear errors instead of returning `None` +* 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]: