gh-133400: Fixed Ctrl+D (^D) behavior in :mod:_pyrepl module#133883
gh-133400: Fixed Ctrl+D (^D) behavior in :mod:_pyrepl module#133883ambv merged 4 commits intopython:mainfrom
_pyrepl module#133883Conversation
|
This is not ideal: >>> if True:
...
File "<python-input-2>", line 1
if True:
^
IndentationError: expected an indented block after 'if' statement on line 1
>>> |
This fix is to correctly handle the issue of Ctrl+D to exit multi-line mode. What do you think the expected behavior should be? |
|
@ambv FWIW I tested this PR on my Mac (main branch, latest, MacOS latest) and it works great. I tried throwing a bunch of other unclosed constructs (e.g. {, [, etc.) and none exhibited this error either. |
|
@StanFromIreland Are you suggesting that the error message in the if True: case could be more clear? The fact that the user isn't supplying a valid indented block after the if True: is indeed a problem the language needs to flag, so I'm curious what specific wording you think might be more clear. Also it seems to me like this could be a separate Github issue. Do you agree? |
|
Looking at those lines again, I would probably refactor to bring the check for I tried looking at the test cases a little bit, but I haven't been able to figure out how best to add the tests yet. What I wanted to test was that the following happens:
I tested that at my own terminal (using the version of the code I pasted above), but I'm not sure the best way to encode that as test cases since @StanFromIreland, this behavior would be consistent with the pre-3.13 REPL, which is what I think we should be aiming for here. |
… to ensure correct termination of input under specific conditions. Co-authored-by: adam j hartz <adam@smatz.net>
92bb608 to
d0dc732
Compare
I tried to make some modifications and add more tests based on what you just said |
Thanks! I just tested this out and it feels right to me (at least if the goal is indeed to mimic the behavior of the old pre-3.13 REPL, which I think is the right thing to do here). Unfortunately I don't have any authority here, but hopefully you'll get some additional code review 🙂 |
|
Sorry, @deepwzh and @ambv, I could not cleanly backport this to |
|
Sorry, @deepwzh and @ambv, I could not cleanly backport this to |
…module (pythonGH-133883) (cherry picked from commit 81959a0) Co-authored-by: DeepWzh <wzh2012@outlook.com> Co-authored-by: adam j hartz <adam@smatz.net>
|
GH-139850 is a backport of this pull request to the 3.14 branch. |
…module (pythonGH-133883) (cherry picked from commit 81959a0) Co-authored-by: DeepWzh <wzh2012@outlook.com> Co-authored-by: adam j hartz <adam@smatz.net>
|
GH-139851 is a backport of this pull request to the 3.13 branch. |
|
Thanks @ambv! |
…GH-133883) (GH-139851) (cherry picked from commit 81959a0) Co-authored-by: DeepWzh <wzh2012@outlook.com> Co-authored-by: adam j hartz <adam@smatz.net>
…GH-133883) (GH-139850) (cherry picked from commit 81959a0) Co-authored-by: DeepWzh <wzh2012@outlook.com> Co-authored-by: adam j hartz <adam@smatz.net>
Fixed Ctrl+D (^D) behavior in :mod:
_pyreplmodule: