Skip to content

Commit

Permalink
Suppress SyntaxWarnings when parsing modules (#2386)
Browse files Browse the repository at this point in the history
Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
  • Loading branch information
cdce8p and jacobtylerwalls authored Feb 19, 2024
1 parent e26f097 commit 07419f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
5 changes: 5 additions & 0 deletions astroid/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 07419f0

Please sign in to comment.