Skip to content

Commit 07419f0

Browse files
Suppress SyntaxWarnings when parsing modules (#2386)
Co-authored-by: Jacob Walls <[email protected]>
1 parent e26f097 commit 07419f0

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ Release date: TBA
2727
* Include modname in AST warnings. Useful for ``invalid escape sequence`` warnings
2828
with Python 3.12.
2929

30+
* Suppress ``SyntaxWarning`` for invalid escape sequences on Python 3.12 when parsing modules.
31+
32+
Closes pylint-dev/pylint#9322
33+
3034

3135

3236
What's New in astroid 3.0.3?

astroid/builder.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
import os
1515
import textwrap
1616
import types
17+
import warnings
1718
from collections.abc import Iterator, Sequence
1819
from io import TextIOWrapper
1920
from tokenize import detect_encoding
2021

2122
from astroid import bases, modutils, nodes, raw_building, rebuilder, util
2223
from astroid._ast import ParserModule, get_parser_module
24+
from astroid.const import PY312_PLUS
2325
from astroid.exceptions import AstroidBuildingError, AstroidSyntaxError, InferenceError
2426
from astroid.manager import AstroidManager
2527

@@ -33,6 +35,9 @@
3335
_STATEMENT_SELECTOR = "#@"
3436
MISPLACED_TYPE_ANNOTATION_ERROR = "misplaced type annotation"
3537

38+
if PY312_PLUS:
39+
warnings.filterwarnings("ignore", "invalid escape sequence", SyntaxWarning)
40+
3641

3742
def open_source_file(filename: str) -> tuple[TextIOWrapper, str, str]:
3843
# pylint: disable=consider-using-with

0 commit comments

Comments
 (0)