Skip to content

PyREPL exits the interpreter on specific input #125666

Closed

Description

@warsaw

Bug report

Bug description:

Playing with the Python 3.13.0 interpreter installed from brew on macOS 14.7 in a Terminal window.

I entered the repl and typed

>>> import math
>>> math.tau
6.283185307179586

Then I hit ctrl-P to get the last line and hit SPC, /, 2. Oddly, the SPC got eaten and the slash ended up right next to the u. I didn't notice that until I hit Enter, at which point the exception occurred and exited the interpreter.

Unfortunately, I cannot reproduce it again.

% python3
Python 3.13.0 (main, Oct  7 2024, 05:02:14) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> math.tau
6.283185307179586
>>> math.tau/ 2
SyntaxError: source code string cannot contain null bytes (<python-input-2>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/local/Cellar/python@3.13/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/_pyrepl/__main__.py", line 6, in <module>
    __pyrepl_interactive_console()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/local/Cellar/python@3.13/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/_pyrepl/main.py", line 59, in interactive_console
    run_multiline_interactive_console(console)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/usr/local/Cellar/python@3.13/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/_pyrepl/simple_interact.py", line 160, in run_multiline_interactive_console
    more = console.push(_strip_final_indent(statement), filename=input_name, _symbol="single")  # type: ignore[call-arg]
  File "/usr/local/Cellar/python@3.13/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/code.py", line 313, in push
    more = self.runsource(source, filename, symbol=_symbol)
  File "/usr/local/Cellar/python@3.13/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/_pyrepl/console.py", line 179, in runsource
    self.showsyntaxerror(filename, source=source)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.13/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/_pyrepl/console.py", line 165, in showsyntaxerror
    super().showsyntaxerror(filename=filename, **kwargs)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.13/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/code.py", line 115, in showsyntaxerror
    self._showtraceback(typ, value, None, source)
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.13/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/code.py", line 140, in _showtraceback
    and not value.text and len(lines) >= value.lineno):
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '>=' not supported between instances of 'int' and 'NoneType'

CPython versions tested on:

3.13

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Oct 17, 2024
  2. devdanzin commented on Oct 19, 2024

    @devdanzin
    Member

    Maybe #88575 has a clue about when SyntaxError.lineno can be None?

    Is it possible that instead of eating the space some invisible character got inserted?

    Edit: oh, it says right on the error that the issue was a null byte.

  3. devdanzin commented on Oct 19, 2024

    @devdanzin
    Member

    Aha, I can reproduce on Linux by pressing Ctrl+Shift+@ followed by Enter:

    >>>
    SyntaxError: source code string cannot contain null bytes (<python-input-5>)
    During handling of the above exception, another exception occurred:
    Traceback (most recent call last):
      File "<frozen runpy>", line 198, in _run_module_as_main
      File "<frozen runpy>", line 88, in _run_code
      File "/home/ubuntu/projects/cpython/Lib/_pyrepl/__main__.py", line 6, in <module>
        __pyrepl_interactive_console()
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
      File "/home/ubuntu/projects/cpython/Lib/_pyrepl/main.py", line 59, in interactive_console
        run_multiline_interactive_console(console)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
      File "/home/ubuntu/projects/cpython/Lib/_pyrepl/simple_interact.py", line 160, in run_multiline_interactive_console
        more = console.push(_strip_final_indent(statement), filename=input_name, _symbol="single")  # type: ignore[call-arg]
      File "/home/ubuntu/projects/cpython/Lib/code.py", line 312, in push
        more = self.runsource(source, filename, symbol=_symbol)
      File "/home/ubuntu/projects/cpython/Lib/_pyrepl/console.py", line 179, in runsource
        self.showsyntaxerror(filename, source=source)
        ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/ubuntu/projects/cpython/Lib/_pyrepl/console.py", line 165, in showsyntaxerror
        super().showsyntaxerror(filename=filename, **kwargs)
        ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/ubuntu/projects/cpython/Lib/code.py", line 114, in showsyntaxerror
        self._showtraceback(typ, value, None, source)
        ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/ubuntu/projects/cpython/Lib/code.py", line 139, in _showtraceback
        and not value.text and len(lines) >= value.lineno):                           ^^^^^^^^^^^^^^^^^^^^^^^^^^
    TypeError: '>=' not supported between instances of 'int' and 'NoneType'

    Edit Ctrl+Space followed by Enter also works, it's probably what you typed by accident.

  4. added a commit that references this issue on Oct 27, 2024
  5. added a commit that references this issue on Oct 27, 2024
  6. added a commit that references this issue on Dec 2, 2024
  7. devdanzin commented on Dec 24, 2024

    @devdanzin
    Member

    This can be closed since #125732 and #126023 were merged.

  8. added a commit that references this issue on Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic-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