Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-40619: Correctly handle error lines in programs without file mode #20090

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

Merged
merged 3 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions 2 Lib/test/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ def bar():
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
30 changes: 5 additions & 25 deletions 30 Parser/pegen/pegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,30 +300,6 @@ raise_tokenizer_init_error(PyObject *filename)
Py_XDECREF(tuple);
}

static inline PyObject *
get_error_line(char *buffer, int is_file)
{
const char *newline;
if (is_file) {
newline = strrchr(buffer, '\n');
} else {
newline = strchr(buffer, '\n');
}

if (is_file) {
while (newline > buffer && newline[-1] == '\n') {
--newline;
}
}

if (newline) {
return PyUnicode_DecodeUTF8(buffer, newline - buffer, "replace");
}
else {
return PyUnicode_DecodeUTF8(buffer, strlen(buffer), "replace");
}
}

static int
tokenizer_error(Parser *p)
{
Expand Down Expand Up @@ -422,7 +398,11 @@ _PyPegen_raise_error_known_location(Parser *p, PyObject *errtype,
}

if (!error_line) {
error_line = get_error_line(p->tok->buf, p->start_rule == Py_file_input);
Py_ssize_t size = p->tok->inp - p->tok->buf;
if (size && p->tok->buf[size-1] == '\n') {
size--;
}
error_line = PyUnicode_DecodeUTF8(p->tok->buf, size, "replace");
if (!error_line) {
goto error;
}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.