Repository navigation
Fix --pretty crash on EOF syntax errors - #22430
Conversation
67257ec to
e0b9c1e
Compare
This comment has been minimized.
This comment has been minimized.
chrikrah
left a comment
There was a problem hiding this comment.
@lianxiaozhi nothing blocks this from my side.
# head e0b9c1e, Python 3.12, tree from git archive
$ python -m pytest -q -n 4 mypy/test/testcmdline.py
149 passed
# errors.py from b83696e, new case kept
$ python -m pytest -q mypy/test/testcmdline.py -k testShowSourceCodeSnippetsUnexpectedEOF
1 failed # IndexError: list index out of range
# a.py is `x = (1,`, ast_serialize 0.13.1
$ python -m mypy --pretty --no-incremental a.py
a.py:2: error: Unexpected EOF while parsing [syntax]
$ python -m mypy --pretty --no-incremental --no-native-parser a.py
a.py:1: error: '(' was never closed [syntax]
x = (1,
^
# not run: the full mypy suite
non-blocking: the guard belongs here either way. The line 2 comes from the native parser, so I'll open that in mypyc/ast_serialize today.
hauntsaninja
left a comment
There was a problem hiding this comment.
Thanks! cmdline tests are slow, could you try a check-columns.test or somewhere else (assuming it would have demonstrated the crash)?
|
@hauntsaninja Thanks! I tried @chrikrah Thanks for verifying the fix and looking into the parser behavior. |
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Fixes #22424.
EOF errors can point past the last source line. Check the line number before adding a source snippet so
--prettyreports the syntax error without crashing. Add a regression test.