2929import os
3030import pkgutil
3131import pydoc
32+ import re
3233import shlex
3334import subprocess
3435import 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