aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2021-05-30 16:07:31 +0300
committerMatti Picus <matti.picus@gmail.com>2021-05-30 16:07:31 +0300
commit360dc1e1ad093ab19235b49e1920abaf620ed654 (patch)
tree55e87e45b3f836712c02d4649e892582fecaa427 /lib-python/3/traceback.py
parentfix (diff)
parentupdate to stdlib3.8.10 (diff)
downloadpypy-360dc1e1ad093ab19235b49e1920abaf620ed654.tar.gz
pypy-360dc1e1ad093ab19235b49e1920abaf620ed654.tar.bz2
pypy-360dc1e1ad093ab19235b49e1920abaf620ed654.zip
merge branch to check stdlib3.8.10
Diffstat (limited to 'lib-python/3/traceback.py')
-rw-r--r--lib-python/3/traceback.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib-python/3/traceback.py b/lib-python/3/traceback.py
index dd9843e49d..dc7b188ac9 100644
--- a/lib-python/3/traceback.py
+++ b/lib-python/3/traceback.py
@@ -515,7 +515,8 @@ class TracebackException:
if exc_type and issubclass(exc_type, SyntaxError):
# Handle SyntaxError's specially
self.filename = exc_value.filename
- self.lineno = str(exc_value.lineno)
+ lno = exc_value.lineno
+ self.lineno = str(lno) if lno is not None else None
self.text = exc_value.text
self.offset = exc_value.offset
self.msg = exc_value.msg
@@ -569,9 +570,12 @@ class TracebackException:
return
# It was a syntax error; show exactly where the problem was found.
- filename = self.filename or "<string>"
- lineno = str(self.lineno) or '?'
- yield ' File "{}", line {}\n'.format(filename, lineno)
+ filename_suffix = ''
+ if self.lineno is not None:
+ yield ' File "{}", line {}\n'.format(
+ self.filename or "<string>", self.lineno)
+ elif self.filename is not None:
+ filename_suffix = ' ({})'.format(self.filename)
badline = self.text
offset = self.offset
@@ -585,7 +589,7 @@ class TracebackException:
caretspace = ((c.isspace() and c or ' ') for c in caretspace)
yield ' {}^\n'.format(''.join(caretspace))
msg = self.msg or "<no detail available>"
- yield "{}: {}\n".format(stype, msg)
+ yield "{}: {}{}\n".format(stype, msg, filename_suffix)
def format(self, *, chain=True):
"""Format the exception.