diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2023-10-13 09:25:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-13 09:25:37 (GMT) |
commit | e1d8c65e1df990ef8d61b8912742e1a021395e78 (patch) | |
tree | 84956c1158b3baf33d9836a5a87b8fa6b57a0428 /Lib/traceback.py | |
parent | 898f531996f2c5399b13811682c578c4fd08afaa (diff) | |
download | cpython-e1d8c65e1df990ef8d61b8912742e1a021395e78.zip cpython-e1d8c65e1df990ef8d61b8912742e1a021395e78.tar.gz cpython-e1d8c65e1df990ef8d61b8912742e1a021395e78.tar.bz2 |
gh-110805: Allow the repl to show source code and complete tracebacks (#110775)
Diffstat (limited to 'Lib/traceback.py')
-rw-r--r-- | Lib/traceback.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Lib/traceback.py b/Lib/traceback.py index 12fcdad..7cc84b9 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -434,7 +434,6 @@ class StackSummary(list): co = f.f_code filename = co.co_filename name = co.co_name - fnames.add(filename) linecache.lazycache(filename, f.f_globals) # Must defer line lookups until we have called checkcache. @@ -447,6 +446,7 @@ class StackSummary(list): end_lineno=end_lineno, colno=colno, end_colno=end_colno)) for filename in fnames: linecache.checkcache(filename) + # If immediate lookup was desired, trigger lookups now. if lookup_lines: for f in result: @@ -479,8 +479,12 @@ class StackSummary(list): gets called for every frame to be printed in the stack summary. """ row = [] - row.append(' File "{}", line {}, in {}\n'.format( - frame_summary.filename, frame_summary.lineno, frame_summary.name)) + if frame_summary.filename.startswith("<python-input"): + row.append(' File "<stdin>", line {}, in {}\n'.format( + frame_summary.lineno, frame_summary.name)) + else: + row.append(' File "{}", line {}, in {}\n'.format( + frame_summary.filename, frame_summary.lineno, frame_summary.name)) if frame_summary.line: stripped_line = frame_summary.line.strip() row.append(' {}\n'.format(stripped_line)) |