bpo-30953: Improve error messages and add tests for jumping (GH-6196)

into/out of an except block.
This commit is contained in:
Serhiy Storchaka 2018-03-23 14:46:45 +02:00 committed by GitHub
parent 702f8f3611
commit 397466dfd9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 12 deletions

View file

@ -277,8 +277,12 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno)
int first_in = target_addr <= f->f_lasti && f->f_lasti <= addr;
int second_in = target_addr <= new_lasti && new_lasti <= addr;
if (first_in != second_in) {
PyErr_SetString(PyExc_ValueError,
"can't jump into or out of a 'finally' block");
op = code[target_addr];
PyErr_Format(PyExc_ValueError,
"can't jump %s %s block",
second_in ? "into" : "out of",
(op == DUP_TOP || op == POP_TOP) ?
"an 'except'" : "a 'finally'");
return -1;
}
break;