Skip to content

Commit 646ee86

Browse files
committed
address review: save history *after* statement was executed
1 parent 0a90c5e commit 646ee86

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

Lib/_pyrepl/simple_interact.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ def maybe_run_command(statement: str) -> bool:
142142
if maybe_run_command(statement):
143143
continue
144144

145+
input_name = f"<python-input-{input_n}>"
146+
more = console.push(_strip_final_indent(statement), filename=input_name, _symbol="single") # type: ignore[call-arg]
147+
assert not more
145148
try:
146149
append_history_file()
147150
except (FileNotFoundError, PermissionError, OSError) as e:
148151
warnings.warn(f"failed to open the history file for writing: {e}")
149-
input_name = f"<python-input-{input_n}>"
150-
more = console.push(_strip_final_indent(statement), filename=input_name, _symbol="single") # type: ignore[call-arg]
151-
assert not more
152152
input_n += 1
153153
except KeyboardInterrupt:
154154
r = _get_reader()

Lib/test/test_pyrepl/test_pyrepl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ def test_history_survive_crash(self):
13601360
history = pathlib.Path(hfile.name).read_text()
13611361
self.assertIn("spam", history)
13621362
self.assertIn("time", history)
1363-
self.assertIn("sleep", history)
1363+
self.assertNotIn("sleep", history)
13641364
self.assertNotIn("preved", history)
13651365

13661366
def test_keyboard_interrupt_after_isearch(self):
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
In PyREPL, append a new entry to the ``PYTHON_HISTORY`` file *before* every
2-
statement was executed. This should preserve command-line history after
3-
interpreter is terminated. Patch by Sergey B Kirpichev.
1+
In PyREPL, append a new entry to the ``PYTHON_HISTORY`` file *after* every
2+
statement. This should preserve command-line history after interpreter is
3+
terminated. Patch by Sergey B Kirpichev.

0 commit comments

Comments
 (0)