Skip to content

New repl closes CLI session on SyntaxError inside of the match statement #119555

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

Closed
skirpichev opened this issue May 25, 2024 · 1 comment
Closed
Labels
3.13 bugs and security fixes 3.14 bugs and security fixes topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error

Comments

@skirpichev
Copy link
Member

skirpichev commented May 25, 2024

Bug report

Bug description:

>>> match 1:
...     case {0: _, 0j: _}:
...         pass
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/sk/src/cpython/Lib/_pyrepl/__main__.py", line 47, in <module>
    interactive_console()
    ~~~~~~~~~~~~~~~~~~~^^
  File "/home/sk/src/cpython/Lib/_pyrepl/__main__.py", line 44, in interactive_console
    return run_interactive(mainmodule)
  File "/home/sk/src/cpython/Lib/_pyrepl/simple_interact.py", line 176, in run_multiline_interactive_console
    more = console.push(_strip_final_indent(statement), filename=input_name, _symbol="single")  # type: ignore[call-arg]
  File "/home/sk/src/cpython/Lib/code.py", line 303, in push
    more = self.runsource(source, filename, symbol=_symbol)
  File "/home/sk/src/cpython/Lib/_pyrepl/simple_interact.py", line 98, in runsource
    code = compile(item, filename, the_symbol)
  File "<python-input-0>", line 2
SyntaxError: mapping pattern checks duplicate key (0j)

At that point I'm in the system shell...

C.f.:

>>> def f():
...     raise ValueError("boo!")
...     
>>> f()
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    f()
    ~^^
  File "<python-input-0>", line 2, in f
    raise ValueError("boo!")
ValueError: boo!
>>>  3.to_bytes()
  File "<unknown>", line 1
    3.to_bytes()
     ^
SyntaxError: invalid decimal literal

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

@skirpichev skirpichev added the type-bug An unexpected behavior, bug, or error label May 25, 2024
@AlexWaygood AlexWaygood added topic-repl Related to the interactive shell 3.13 bugs and security fixes 3.14 bugs and security fixes labels May 25, 2024
@skirpichev
Copy link
Member Author

Seems to be fixed by one-liner:

diff --git a/Lib/_pyrepl/simple_interact.py b/Lib/_pyrepl/simple_interact.py
index 8ab4dab757..f6857c5967 100644
--- a/Lib/_pyrepl/simple_interact.py
+++ b/Lib/_pyrepl/simple_interact.py
@@ -96,7 +96,7 @@ def runsource(self, source, filename="<input>", symbol="single"):
             item = wrapper([stmt])
             try:
                 code = compile(item, filename, the_symbol)
-            except (OverflowError, ValueError):
+            except (OverflowError, ValueError, SyntaxError):
                     self.showsyntaxerror(filename)
                     return False
 

I'm working on a pr.

skirpichev added a commit to skirpichev/cpython that referenced this issue May 25, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 29, 2024
…oloredConsole (pythonGH-119557)

(cherry picked from commit 86d1a1a)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
noahbkim pushed a commit to hudson-trading/cpython that referenced this issue Jul 11, 2024
estyxx pushed a commit to estyxx/cpython that referenced this issue Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 bugs and security fixes topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants