Correct location for syntax error in try-except (GH-25939)

This commit is contained in:
Mark Shannon 2021-05-06 13:38:50 +01:00 committed by GitHub
parent 60ba0b6847
commit 8d4b18429d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 2 deletions

View file

@ -3165,9 +3165,9 @@ compiler_try_except(struct compiler *c, stmt_ty s)
for (i = 0; i < n; i++) {
excepthandler_ty handler = (excepthandler_ty)asdl_seq_GET(
s->v.Try.handlers, i);
SET_LOC(c, handler);
if (!handler->v.ExceptHandler.type && i < n-1)
return compiler_error(c, "default 'except:' must be last");
SET_LOC(c, handler);
except = compiler_new_block(c);
if (except == NULL)
return 0;