In IPython master, displayhook can currently be triggered more than one time per input. Previously we had talked about only allowing it to trigger once per input. We need to decide on the desired behavior and implement it. R. Kern brought up the good point that we don't need to handle this in the block splitter code, but could handle it in our custom displayhook code by allow the trigger to happen multiple times, but only showing the last result.
I think handling it in displayhook would lead to unexpected behaviour. Specifically, if I do for a in range(5): a, I would expect to see either five outputs or none.
for a in range(5): a
Two possible ways to do this in AST side: we can run the last node interactively only if it's an expression, or we can run the last node which is an expression interactively, then switch back to exec mode for the remaining nodes. I think I would find the former behaviour less surprising (that is, only the last node can produce output).
If people want to test it, here's a branch doing what I think is the most intuitive behaviour:
Actually, in its current state, the history can store any number of outputs, by sticking them into a JSON list. If we like this behaviour, I'll change that back so that it expects 0 or 1 output, and just stores it individually.
Branch merged at bb38481, so I'm closing this issue.