Skip to content

traceback shows wrong source code in basic REPL when PYTHONSTARTUP is set #137576

@ilupin

Description

@ilupin

Bug report

Bug description:

Start python with the basic repl and a PYTHONSTARTUP file

export PYTHON_BASIC_REPL=1; echo 'import math' > /tmp/foo.py; export PYTHONSTARTUP="/tmp/foo.py"; python

type 1/0 and the traceback shows

Python 3.13.5 | packaged by Anaconda, Inc. | (main, Jun 12 2025, 16:09:02) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1/0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    import math
    ^^^
ZeroDivisionError: division by zero
>>> 

Expected behavior (i.e. export PYTHON_BASIC_REPL=1; unset PYTHONSTARTUP; python):

>>> 1/0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    1/0
    ~^~
ZeroDivisionError: division by zero
>>>

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions