Skip to content

Commit 42896c2

Browse files
Reflect better TokenError linenos in python 3.12
1 parent dfb47db commit 42896c2

File tree

7 files changed

+17
-5
lines changed

7 files changed

+17
-5
lines changed

pylint/lint/pylinter.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,13 @@ def _check_astroid_module(
10431043
try:
10441044
tokens = utils.tokenize_module(node)
10451045
except tokenize.TokenError as ex:
1046-
self.add_message("syntax-error", line=ex.args[1][0], args=ex.args[0])
1046+
self.add_message(
1047+
"syntax-error",
1048+
line=ex.args[1][0],
1049+
col_offset=ex.args[1][1],
1050+
args=ex.args[0],
1051+
confidence=HIGH,
1052+
)
10471053
return None
10481054

10491055
if not node.pure_python:

tests/functional/t/tokenize_error.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""A module that is accepted by Python but rejected by tokenize.
2-
3-
The problem is the trailing line continuation at the end of the line,
1+
"""The problem is the trailing line continuation at the end of the line,
42
which produces a TokenError."""
53
# +2: [syntax-error]
64
""\

tests/functional/t/tokenize_error.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
[testoptions]
2+
max_pyver=3.12

tests/functional/t/tokenize_error.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
syntax-error:7:0:None:None::EOF in multi-line statement:UNDEFINED
1+
syntax-error:5:0:None:None::EOF in multi-line statement:HIGH
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""The problem is the trailing line continuation at the end of the line,
2+
which produces a TokenError."""
3+
# +1: [syntax-error]
4+
""\
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[testoptions]
2+
min_pyver=3.12
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
syntax-error:4:4:None:None::unexpected EOF in multi-line statement:HIGH

0 commit comments

Comments
 (0)