Skip to content

Interactive interpreter prints wrong lines in exception traceback when PYTHON_BASIC_REPL=1 and startup file is loaded #139321

@schuelermine

Description

@schuelermine

Bug report

Bug description:

  1. Create a Python file ./startup.py:
    # Python startup file LINE 1
    # Python startup file LINE 2
  2. Run PYTHONSTARTUP=./startup.py PYTHON_BASIC_REPL=1 python3
  3. Run
    >>> undefined
    Expected output:
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
        undefined
    NameError: name 'undefined' is not defined
    
    Actual output:
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
        # Python startup file LINE 1
    NameError: name 'undefined' is not defined
    
  4. Run
    >>> while True:
    ...     undefined
    Expected output:
    Traceback (most recent call last):
      File "<stdin>", line 2, in <module>
        undefined
    NameError: name 'undefined' is not defined
    
    Actual output:
    Traceback (most recent call last):
      File "<stdin>", line 2, in <module>
        # Python startup file LINE 2
    NameError: name 'undefined' is not defined
    
  5. Run
    >>> while True:
    ...     pass
    ...     undefined
    Here, the output is correct and as expected:
    Traceback (most recent call last):
      File "<stdin>", line 3, in <module>
        undefined
    NameError: name 'undefined' is not defined
    

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions