Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions IPython/core/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,9 @@ def extract_hist_ranges(ranges_str: str) -> Iterable[Tuple[int, int, Optional[in
return

for range_str in ranges_str.split():
if re.match(r'~\d+', range_str):
yield (int(range_str.replace("~", "-")), 1, None)
continue
rmatch = range_re.match(range_str)
if not rmatch:
continue
Expand Down
26 changes: 16 additions & 10 deletions IPython/core/tests/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from tempfile import TemporaryDirectory
# our own packages
from traitlets.config.loader import Config
import pytest

from IPython.core.history import HistoryAccessor, HistoryManager, extract_hist_ranges

Expand Down Expand Up @@ -152,16 +153,21 @@ def test_history():
ip.history_manager = hist_manager_ori


def test_extract_hist_ranges():
instr = "1 2/3 ~4/5-6 ~4/7-~4/9 ~9/2-~7/5 ~10/"
expected = [(0, 1, 2), # 0 == current session
(2, 3, 4),
(-4, 5, 7),
(-4, 7, 10),
(-9, 2, None), # None == to end
(-8, 1, None),
(-7, 1, 6),
(-10, 1, None)]


@pytest.mark.parametrize(
"instr, expected",
[
("1", [(0, 1, 2)]),
("2/3", [(2, 3, 4)]),
("~4/5-6", [(-4, 5, 7)]),
("~4/7-~4/9", [(-4, 7, 10)]),
("~9/2-~7/5", [(-9, 2, None)]),
("~10/", [(-10, 1, None)]),
("~4", [(-4, 1, None)]),
],
)
def test_extract_hist_ranges(instr, expected):
actual = list(extract_hist_ranges(instr))
assert actual == expected

Expand Down
Loading