Skip to content

Commit ad83b72

Browse files
committed
transform_statements: meaningful error message on user function fail
1 parent dd8f612 commit ad83b72

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

unpythonic/syntax/util.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,11 @@ def rec(tree):
444444
handler.body = rec(handler.body)
445445
elif type(tree) is list: # multiple-statement body in AST
446446
return [output_stmt for input_stmt in tree for output_stmt in rec(input_stmt)]
447-
return f(tree) # a single statement
447+
# A single statement. Transform it.
448+
replacement = f(tree)
449+
if not isinstance(replacement, list):
450+
raise TypeError("`f` must return a list of statements, got {} with value '{}'".format(type(replacement), replacement)) # pragma: no cover
451+
return replacement
448452
return rec(body)
449453

450454
def splice(tree, rep, tag):

0 commit comments

Comments
 (0)