Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress SyntaxWarnings when parsing modules #2386

Merged
merged 4 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ``SyntaxWarnings`` when parsing modules.
cdce8p marked this conversation as resolved.
Show resolved Hide resolved

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
Loading