Skip to content

Commit 0cb8163

Browse files
fix #591 changing stack trace linenos
1 parent 31e785a commit 0cb8163

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

bpython/repl.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import os
3030
import pkgutil
3131
import pydoc
32+
import re
3233
import shlex
3334
import subprocess
3435
import sys
@@ -133,6 +134,9 @@ def showsyntaxerror(self, filename=None):
133134
# Stuff in the right filename and right lineno
134135
if not py3:
135136
lineno -= 1
137+
if re.match(r'<bpython-input-\d+>', filename):
138+
filename = '<input>'
139+
# strip linecache line number
136140
value = SyntaxError(msg, (filename, lineno, offset, line))
137141
sys.last_value = value
138142
list = traceback.format_exception_only(type, value)
@@ -149,9 +153,14 @@ def showtraceback(self):
149153
sys.last_traceback = tb
150154
tblist = traceback.extract_tb(tb)
151155
del tblist[:1]
152-
# Set the right lineno (encoding header adds an extra line)
153-
if not py3:
154-
for i, (fname, lineno, module, something) in enumerate(tblist):
156+
157+
for i, (fname, lineno, module, something) in enumerate(tblist):
158+
# strip linecache line number
159+
if re.match(r'<bpython-input-\d+>', fname):
160+
fname = '<input>'
161+
tblist[i] = (fname, lineno, module, something)
162+
# Set the right lineno (encoding header adds an extra line)
163+
if not py3:
155164
if fname == '<input>':
156165
tblist[i] = (fname, lineno - 1, module, something)
157166

0 commit comments

Comments
 (0)