Suppress SyntaxWarnings for Python 3.14 when parsing modules (#2853)
diff --git a/ChangeLog b/ChangeLog
index 08b9605..426a9b6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -21,6 +21,9 @@
* 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 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]: