Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyREPL exits the interpreter on specific input #125666

Closed
warsaw opened this issue Oct 17, 2024 · 3 comments
Closed

PyREPL exits the interpreter on specific input #125666

warsaw opened this issue Oct 17, 2024 · 3 comments
Labels
topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error

Comments

@warsaw
Copy link
Member

warsaw commented Oct 17, 2024

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

@warsaw warsaw added the type-bug An unexpected behavior, bug, or error label Oct 17, 2024
@tomasr8 tomasr8 added the topic-repl Related to the interactive shell label Oct 17, 2024
@devdanzin
Copy link
Contributor

devdanzin commented Oct 19, 2024

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.

@devdanzin
Copy link
Contributor

devdanzin commented Oct 19, 2024

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.

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 27, 2024
…ythonGH-125732)

(cherry picked from commit 44becb8)

Co-authored-by: devdanzin <74280297+devdanzin@users.noreply.github.com>
Yhg1s pushed a commit that referenced this issue Dec 2, 2024
…H-125732) (#126023)

gh-125666: Avoid PyREPL exiting when a null byte is in input (GH-125732)
(cherry picked from commit 44becb8)

Co-authored-by: devdanzin <74280297+devdanzin@users.noreply.github.com>
@devdanzin
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants