mirror of
https://github.com/python/cpython.git
synced 2025-08-09 19:38:42 +00:00
[3.12] gh-103956: Fix trace
output in case of missing source line (GH-103958) (GH-118832)
Print only filename with lineno if linecache.getline() returns an empty string.
(cherry picked from commit 7c87ce777b
)
Co-authored-by: Radislav Chugunov <52372310+chgnrdv@users.noreply.github.com>
This commit is contained in:
parent
e9539568be
commit
0d626760a4
3 changed files with 38 additions and 4 deletions
16
Lib/trace.py
16
Lib/trace.py
|
@ -559,8 +559,12 @@ class Trace:
|
|||
if self.start_time:
|
||||
print('%.2f' % (_time() - self.start_time), end=' ')
|
||||
bname = os.path.basename(filename)
|
||||
print("%s(%d): %s" % (bname, lineno,
|
||||
linecache.getline(filename, lineno)), end='')
|
||||
line = linecache.getline(filename, lineno)
|
||||
print("%s(%d)" % (bname, lineno), end='')
|
||||
if line:
|
||||
print(": ", line, end='')
|
||||
else:
|
||||
print()
|
||||
return self.localtrace
|
||||
|
||||
def localtrace_trace(self, frame, why, arg):
|
||||
|
@ -572,8 +576,12 @@ class Trace:
|
|||
if self.start_time:
|
||||
print('%.2f' % (_time() - self.start_time), end=' ')
|
||||
bname = os.path.basename(filename)
|
||||
print("%s(%d): %s" % (bname, lineno,
|
||||
linecache.getline(filename, lineno)), end='')
|
||||
line = linecache.getline(filename, lineno)
|
||||
print("%s(%d)" % (bname, lineno), end='')
|
||||
if line:
|
||||
print(": ", line, end='')
|
||||
else:
|
||||
print()
|
||||
return self.localtrace
|
||||
|
||||
def localtrace_count(self, frame, why, arg):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue