Skip to content
This repository

Magic 'range' crash if greater than len(input_hist) #804

Merged
merged 1 commit into from over 2 years ago

2 participants

Matthias Bussonnier Thomas Kluyver
Matthias Bussonnier
Collaborator

when calling a magic with a range (eg %save filename 1-500) and an history
smaller than 500 IPython.core.HistoryManager/_get_range_session will crash.

this commit fix it by setting the stop argument to at maximum len(input_history)

by the way, is there away to use the negative indexing to count from the end...
something like %save filename 1:-1 to save the whole current session without thinking of the last prompt number ?

Matthias Bussonnier cut if history range asked is bigger than history length
	when calling a magic with a range (eg %save filename 1-500) and an history
	smaller than 500
	IPython.core.HistoryManager/_get_range_session
	would crash
8543f0a
Thomas Kluyver
Collaborator

Thanks, that's definitely a good idea. I think it should also be possible to check this as part of the history tests, if you'd like to add that.

There's not at present any way to get a whole session, but I'd like to add one. I'd probably do it like 1- or 1-end. I'd probably avoid using - as minus, because - is already used there for ranges. I'm also planning to add separate tools for browsing and dumping history.

Thomas Kluyver takluyver merged commit 8543f0a into from September 29, 2011
Thomas Kluyver takluyver closed this September 29, 2011
Thomas Kluyver
Collaborator

Thanks - I've added a quick test and merged it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Sep 19, 2011
Matthias Bussonnier cut if history range asked is bigger than history length
	when calling a magic with a range (eg %save filename 1-500) and an history
	smaller than 500
	IPython.core.HistoryManager/_get_range_session
	would crash
8543f0a
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 1 addition and 1 deletion. Show diff stats Hide diff stats

  1. 2  IPython/core/history.py
2  IPython/core/history.py
@@ -303,7 +303,7 @@ def _get_range_session(self, start=1, stop=None, raw=True, output=False):
303 303
         n = len(input_hist)
304 304
         if start < 0:
305 305
             start += n
306  
-        if not stop:
  306
+        if not stop or (stop > n):
307 307
             stop = n
308 308
         elif stop < 0:
309 309
             stop += n
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.