Skip to content

Commit 7694230

Browse files
authored
Coerce catch/finally clause inputs to lists (#157)
1 parent c668182 commit 7694230

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

basilisp/compiler.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,6 @@ def _catch_ast(ctx: CompilerContext, form: llist.List) -> ast.ExceptHandler:
11701170

11711171
def _finally_ast(ctx: CompilerContext, form: llist.List) -> ASTStream:
11721172
"""Generate Python AST nodes for `finally` forms."""
1173-
assert isinstance(form, llist.List)
11741173
assert form.first == _FINALLY
11751174
assert len(form) >= 2
11761175

@@ -1224,8 +1223,12 @@ def _try_ast(ctx: CompilerContext, form: llist.List) -> ASTStream:
12241223
if len(finallys) not in [0, 1]:
12251224
raise CompilerException("Only one finally clause may be provided in a try/catch block") from None
12261225

1227-
catch_exprs: List[ast.AST] = seq(clauses.get("catch", [])).map(lambda f: _catch_ast(ctx, f)).to_list()
1228-
final_exprs: List[ast.AST] = seq(finallys).flat_map(lambda f: _finally_ast(ctx, f)).to_list()
1226+
catch_exprs: List[ast.AST] = seq(clauses.get("catch", [])) \
1227+
.map(lambda f: _catch_ast(ctx, llist.list(f))) \
1228+
.to_list()
1229+
final_exprs: List[ast.AST] = seq(finallys) \
1230+
.flat_map(lambda f: _finally_ast(ctx, llist.list(f))) \
1231+
.to_list()
12291232

12301233
# Start building up the try/except block that will be inserted
12311234
# into a function to expressionize it

0 commit comments

Comments
 (0)