Skip to content

Commit

Permalink
Reflect better TokenError linenos in python 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Jul 14, 2023
1 parent dfb47db commit 42896c2
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 5 deletions.
8 changes: 7 additions & 1 deletion pylint/lint/pylinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,13 @@ def _check_astroid_module(
try:
tokens = utils.tokenize_module(node)
except tokenize.TokenError as ex:
self.add_message("syntax-error", line=ex.args[1][0], args=ex.args[0])
self.add_message(
"syntax-error",
line=ex.args[1][0],
col_offset=ex.args[1][1],
args=ex.args[0],
confidence=HIGH,
)
return None

if not node.pure_python:
Expand Down
4 changes: 1 addition & 3 deletions tests/functional/t/tokenize_error.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""A module that is accepted by Python but rejected by tokenize.
The problem is the trailing line continuation at the end of the line,
"""The problem is the trailing line continuation at the end of the line,
which produces a TokenError."""
# +2: [syntax-error]
""\
1 change: 1 addition & 0 deletions tests/functional/t/tokenize_error.rc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
[testoptions]
max_pyver=3.12
2 changes: 1 addition & 1 deletion tests/functional/t/tokenize_error.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
syntax-error:7:0:None:None::EOF in multi-line statement:UNDEFINED
syntax-error:5:0:None:None::EOF in multi-line statement:HIGH
4 changes: 4 additions & 0 deletions tests/functional/t/tokenize_error_py312.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""The problem is the trailing line continuation at the end of the line,
which produces a TokenError."""
# +1: [syntax-error]
""\
2 changes: 2 additions & 0 deletions tests/functional/t/tokenize_error_py312.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[testoptions]
min_pyver=3.12
1 change: 1 addition & 0 deletions tests/functional/t/tokenize_error_py312.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
syntax-error:4:4:None:None::unexpected EOF in multi-line statement:HIGH

0 comments on commit 42896c2

Please sign in to comment.