diff --git a/ChangeLog b/ChangeLog index bf230c9864..aedde4bdd4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -27,6 +27,10 @@ Release date: TBA * Include modname in AST warnings. Useful for ``invalid escape sequence`` warnings with Python 3.12. +* Suppress ``SyntaxWarning`` for invalid escape sequences on Python 3.12 when parsing modules. + + Closes pylint-dev/pylint#9322 + What's New in astroid 3.0.3? diff --git a/astroid/builder.py b/astroid/builder.py index 1a4c10ecfe..cff859124e 100644 --- a/astroid/builder.py +++ b/astroid/builder.py @@ -14,12 +14,14 @@ import os import textwrap import types +import warnings from collections.abc import Iterator, Sequence from io import TextIOWrapper from tokenize import detect_encoding 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.exceptions import AstroidBuildingError, AstroidSyntaxError, InferenceError from astroid.manager import AstroidManager @@ -33,6 +35,9 @@ _STATEMENT_SELECTOR = "#@" MISPLACED_TYPE_ANNOTATION_ERROR = "misplaced type annotation" +if PY312_PLUS: + warnings.filterwarnings("ignore", "invalid escape sequence", SyntaxWarning) + def open_source_file(filename: str) -> tuple[TextIOWrapper, str, str]: # pylint: disable=consider-using-with