Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions Lib/test/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def baz():
'''quux'''
""", 9, 20)
check("pass\npass\npass\n(1+)\npass\npass\npass", 4, 4)
check("(1+)", 1, 4)

# Errors thrown by symtable.c
check('x = [(yield i) for i in range(3)]', 1, 5)
Expand Down
4 changes: 3 additions & 1 deletion Parser/pegen/pegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,9 @@ _PyPegen_raise_error_known_location(Parser *p, PyObject *errtype,

if (!error_line) {
Py_ssize_t size = p->tok->inp - p->tok->buf;
error_line = PyUnicode_DecodeUTF8(p->tok->buf, size ? size - 1: size, "replace");
error_line = PyUnicode_DecodeUTF8(p->tok->buf,
p->tok->buf[size-1] == '\n' ? size - 1 : size,
"replace");
if (!error_line) {
goto error;
}
Expand Down