-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
gh-133400: Fixed Ctrl+D (^D) behavior in :mod:_pyrepl
module
#133883
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
base: main
Are you sure you want to change the base?
Conversation
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 🙂 |
Fixed Ctrl+D (^D) behavior in :mod:
_pyrepl
module: