gh-137576: Fix for Basic REPL showing incorrect code in tracebacks wi… · python/cpython@04f8ef6 · GitHub
Skip to content

Commit 04f8ef6

Browse files
adqmEclips4
andauthored
gh-137576: Fix for Basic REPL showing incorrect code in tracebacks with PYTHONSTARTUP (#137625)
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
1 parent 8b8bd3d commit 04f8ef6

4 files changed

Lines changed: 90 additions & 3 deletions

File tree

Lib/test/test_repl.py

Lines changed: 62 additions & 0 deletions

Lib/traceback.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ def format_frame_summary(self, frame_summary, **kwargs):
541541
colorize = kwargs.get("colorize", False)
542542
row = []
543543
filename = frame_summary.filename
544-
if frame_summary.filename.startswith("<stdin>-"):
544+
if frame_summary.filename.startswith("<stdin-") and frame_summary.filename.endswith('>'):
545545
filename = "<stdin>"
546546
if colorize:
547547
theme = _colorize.get_theme(force_color=True).traceback
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix for incorrect source code being shown in tracebacks from the Basic REPL
2+
when :envvar:`PYTHONSTARTUP` is given. Patch by Adam Hartz.

Python/pythonrun.c

Lines changed: 25 additions & 2 deletions

0 commit comments

Comments
 (0)