summaryrefslogtreecommitdiffstats
path: root/Python/ast.c
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2021-12-14 16:48:15 (GMT)
committerGitHub <noreply@github.com>2021-12-14 16:48:15 (GMT)
commitd60457a6673cf0263213c2f2be02c633ec2e2038 (patch)
tree04461db9079cf30a98c5a4070098f795275aa910 /Python/ast.c
parent850aefc2c651110a784cd5478af9774b1f6287a3 (diff)
downloadcpython-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.c25
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));