Skip to content

Commit 59a8095

Browse files
committed
Handle end_lineno and end_offset in SyntaxError
1 parent deb757d commit 59a8095

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

bpython/repl.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -166,20 +166,21 @@ def showsyntaxerror(self, filename: Optional[str] = None) -> None:
166166
exc_type, value, sys.last_traceback = sys.exc_info()
167167
sys.last_type = exc_type
168168
sys.last_value = value
169-
if filename and exc_type is SyntaxError:
170-
# Work hard to stuff the correct filename in the exception
171-
try:
172-
msg, (dummy_filename, lineno, offset, line) = value.args
173-
except:
174-
# Not the format we expect; leave it alone
175-
pass
176-
else:
177-
# Stuff in the right filename and right lineno
178-
# strip linecache line number
179-
if self.bpython_input_re.match(filename):
180-
filename = "<input>"
181-
value = SyntaxError(msg, (filename, lineno, offset, line))
182-
sys.last_value = value
169+
if (
170+
filename
171+
and exc_type is SyntaxError
172+
and value is not None
173+
and len(value.args) >= 4
174+
):
175+
msg = str(value)
176+
lineno = value.args[1]
177+
offset = value.args[2]
178+
line = value.args[3]
179+
# strip linechache line number
180+
if self.bpython_input_re.match(filename):
181+
filename = "<input>"
182+
value = SyntaxError(msg, (filename, lineno, offset, line))
183+
sys.last_value = value
183184
exc_formatted = traceback.format_exception_only(exc_type, value)
184185
self.writetb(exc_formatted)
185186

0 commit comments

Comments
 (0)