New REPL uses same old plain-text format for storing history entries. But basically it has only one positive pros: it’s simple. Cons: it’s simple! It can’t keep anything else, but commands, no any other meta-information (e.g. timestamps).
One example of it’s current limitations is support for multiple repl, running concurrently. When all repl will be successfully finished, you end with a history from the last repl you quit. Everything else will be lost.
This is something that could be mitigated by using separate PYTHON_HISTORY
environment variables, pointing to individual (per running interpreter) files. Such history files then could be merged, though I can’t imagine anything better than just plain concatenation of all commands (well, perhaps you could find a common preamble for all saved command histories) to the single file. I doubt someone did something like this.
The IPython REPL is much better there. Here is an example (repl 1 and 2 running concurrently with repl 1 opened first):
$ ipython
In [1]: # repl 1
In [2]: 111
Out[2]: 111
In [3]: 333
Out[3]: 333
In [4]: %history
# repl 1
111
333
%history
In [5]: # quit repl 1
In [6]:
$ ipython
In [1]: # repl 2
In [2]: 222
Out[2]: 222
In [3]: 444
Out[3]: 444
In [4]: %history
# repl 2
222
444
%history
In [5]: # quit repl 2
In [6]:
$ ipython
In [1]: # repl 3
In [2]: %history -l 11
# repl 1
111
333
%history
# quit repl 1
# repl 2
222
444
%history
# quit repl 2
# repl 3
Another issue with the current repl is that it’s history lost if the interpreter crashed, because history file updated only at the end of session. This is something that never happened with IPython: statements are saved immediately before execution and are available for all repl, which you will run later.
We can extend old plain-text format, e.g. like the bash does (put timestamps in comments). This (with some care) will allow to automate history merging.
Though, why not adopt IPython approach (maybe even re-use it’s code for history support)? The stdlib has sqlite3 module (plain-text format support could be also kept for compatibility and/or as a fallback), and we can provide a cli interface to work with history file by plain-text tools. (I wonder how common something like grep <foo> ~/.python_history
for people?)
Is that a sane feature proposal or too complex for the default CPython shell?