diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2021-12-14 16:48:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-14 16:48:15 (GMT) |
commit | d60457a6673cf0263213c2f2be02c633ec2e2038 (patch) | |
tree | 04461db9079cf30a98c5a4070098f795275aa910 /Python/ast.c | |
parent | 850aefc2c651110a784cd5478af9774b1f6287a3 (diff) | |
download | cpython-d60457a6673cf0263213c2f2be02c633ec2e2038.zip cpython-d60457a6673cf0263213c2f2be02c633ec2e2038.tar.gz cpython-d60457a6673cf0263213c2f2be02c633ec2e2038.tar.bz2 |
bpo-45292: [PEP-654] add except* (GH-29581)
Diffstat (limited to 'Python/ast.c')
-rw-r--r-- | Python/ast.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Python/ast.c b/Python/ast.c index 0c3121d..607281e 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -817,6 +817,31 @@ validate_stmt(struct validator *state, stmt_ty stmt) (!asdl_seq_LEN(stmt->v.Try.orelse) || validate_stmts(state, stmt->v.Try.orelse)); break; + case TryStar_kind: + if (!validate_body(state, stmt->v.TryStar.body, "TryStar")) + return 0; + if (!asdl_seq_LEN(stmt->v.TryStar.handlers) && + !asdl_seq_LEN(stmt->v.TryStar.finalbody)) { + PyErr_SetString(PyExc_ValueError, "TryStar has neither except handlers nor finalbody"); + return 0; + } + if (!asdl_seq_LEN(stmt->v.TryStar.handlers) && + asdl_seq_LEN(stmt->v.TryStar.orelse)) { + PyErr_SetString(PyExc_ValueError, "TryStar has orelse but no except handlers"); + return 0; + } + for (i = 0; i < asdl_seq_LEN(stmt->v.TryStar.handlers); i++) { + excepthandler_ty handler = asdl_seq_GET(stmt->v.TryStar.handlers, i); + if ((handler->v.ExceptHandler.type && + !validate_expr(state, handler->v.ExceptHandler.type, Load)) || + !validate_body(state, handler->v.ExceptHandler.body, "ExceptHandler")) + return 0; + } + ret = (!asdl_seq_LEN(stmt->v.TryStar.finalbody) || + validate_stmts(state, stmt->v.TryStar.finalbody)) && + (!asdl_seq_LEN(stmt->v.TryStar.orelse) || + validate_stmts(state, stmt->v.TryStar.orelse)); + break; case Assert_kind: ret = validate_expr(state, stmt->v.Assert.test, Load) && (!stmt->v.Assert.msg || validate_expr(state, stmt->v.Assert.msg, Load)); |