From 9091565b688cd9af550db83cee45f82c1c965ee1 Mon Sep 17 00:00:00 2001 From: hsfzxjy Date: Sun, 7 Feb 2021 17:55:59 +0800 Subject: [PATCH] Fix bug: default 'except_' should appear at last --- lambdex/compiler/rules.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lambdex/compiler/rules.py b/lambdex/compiler/rules.py index f5550bf..3019bc2 100644 --- a/lambdex/compiler/rules.py +++ b/lambdex/compiler/rules.py @@ -287,6 +287,7 @@ def r_try(node: ast.Subscript, ctx: Context, clauses: list): handlers = [] orelse_body = [] final_body = [] + default_except_clause = None for clause in clauses[1:]: if clause.name == 'except_': ctx.assert_( @@ -298,8 +299,14 @@ def r_try(node: ast.Subscript, ctx: Context, clauses: list): if clause.no_head(): # bare except type_ = name = None + default_except_clause = clause else: # except with capturing + ctx.assert_( + default_except_clause is None, + "default 'except_' must be last", + lambda: default_except_clause.node, + ) ctx.assert_single_head(clause) type_, name = check_as(ctx, clause.unwrap_head(), ast.Gt, rhs_is_identifier=True)