juliantaylor/ipython — comment on commit e68660659803dfc67b3d05e89f8b3013f6a11cae
File: IPython/frontend/terminal/interactiveshell.py line 241
By takluyver:

I don't think it will, because then when you're doing the stuff to pull out history from the last cell and put it back, you'll add on any lines from raw_input commands in the current cell.

This needs code in two places: storing the hlen_before_cell must occur after the previous cell has executed and before the user starts entering code for the next cell. Modifying the readline history must occur after the user finishes entering code for the current cell, but before that code is run. After the code has executed, we could also remove anything added to readline history by the cell (we have a `readline_no_record` context manager already), but this is less pressing, and there are probably situations when the user wants those things to be available in readline history.