mirror of
https://github.com/python/cpython.git
synced 2025-08-31 22:18:28 +00:00
[3.13] gh-128894: Fix TracebackException._format_syntax_error
on custom SyntaxError
metadata (GH-128946) (#129178)
This commit is contained in:
parent
a379749217
commit
7f6e80a03e
3 changed files with 36 additions and 3 deletions
|
@ -1283,7 +1283,7 @@ class TracebackException:
|
|||
filename_suffix = ' ({})'.format(self.filename)
|
||||
|
||||
text = self.text
|
||||
if text is not None:
|
||||
if isinstance(text, str):
|
||||
# text = " foo\n"
|
||||
# rtext = " foo"
|
||||
# ltext = "foo"
|
||||
|
@ -1292,10 +1292,17 @@ class TracebackException:
|
|||
spaces = len(rtext) - len(ltext)
|
||||
if self.offset is None:
|
||||
yield ' {}\n'.format(ltext)
|
||||
else:
|
||||
elif isinstance(self.offset, int):
|
||||
offset = self.offset
|
||||
if self.lineno == self.end_lineno:
|
||||
end_offset = self.end_offset if self.end_offset not in {None, 0} else offset
|
||||
end_offset = (
|
||||
self.end_offset
|
||||
if (
|
||||
isinstance(self.end_offset, int)
|
||||
and self.end_offset != 0
|
||||
)
|
||||
else offset
|
||||
)
|
||||
else:
|
||||
end_offset = len(rtext) + 1
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue