1
1
import os
2
2
import linecache
3
+ import ast
3
4
4
5
_SPECIAL_DIRS = ('.git' , '.hg' , '.svn' )
5
6
@@ -19,12 +20,20 @@ def normalize_file_path(path):
19
20
dirname = os .path .dirname (dirname )
20
21
return path
21
22
23
+ def _is_ipython_frame (frame ):
24
+ return 'ipython-input' in frame ['filename' ] and frame ['lineno' ] == 1
25
+
22
26
def distill_slash_traceback (err , line_radius = 5 ):
23
27
returned = err .traceback .to_list ()
24
28
for frame in returned :
25
- lines = linecache .getlines (frame ['filename' ])
26
- lineno = frame ['lineno' ]
27
- frame ['code_lines_before' ], _ , frame ['code_lines_after' ] = _splice_lines (lines , lineno - 1 , line_radius )
29
+ if _is_ipython_frame (frame ):
30
+ commands = ast .literal_eval (frame ['locals' ]['In' ]['value' ])
31
+ frame ['code_lines_before' ], frame ['code_line' ], frame ['code_lines_after' ] = _splice_lines (commands , len (commands ) - 1 , line_radius )
32
+ frame ['lineno' ] = len (commands ) - 1
33
+ else :
34
+ lines = linecache .getlines (frame ['filename' ])
35
+ lineno = frame ['lineno' ]
36
+ frame ['code_lines_before' ], _ , frame ['code_lines_after' ] = _splice_lines (lines , lineno - 1 , line_radius )
28
37
return returned
29
38
30
39
def _splice_lines (lines , pivot , margin ):
0 commit comments