-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
bpo-44603: Exit the interpreter if the user types "exit" #27096
Conversation
dc82775
to
f7d1146
Compare
LGTM, I suggest reopening this (button clicked). From a testing perspective, we just want to make sure it doesn't interfere with with what uber interactive console add-on's like IPython already implement that do this. |
From a PR standpoint I think the thing we need was covered in your bug comment: "if there's a single AST node that is a name and the name is "exit" or "quit", the REPL inspects locals and globals to see if the object referred to is a Quitter, and if so it exits" We should be able to add unittest coverage for this in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the purpose of the review, I will be neutral on the proposal. But I do notice that the special behavior is limited to entering exactly 'quit\n' or 'exit\n'. This is stricter than current ^Z behavior.
>>> a^Z
File "<stdin>", line 1
a→
^
SyntaxError: invalid syntax
>>> ^Zb
f:\dev\3x>
Exiting instead of also raising SyntaxError may be a bug.
Changes:
- The reprs of both functions should be changed to eliminate the ()s.
- The code class imitating the REPL should imitate this also. If no syntax error, run same tests on result as ast.parse. But do in a separate function, as here, so subclass can easily disable with def is_exit(code): return False.
When you're done making the requested changes, leave the comment: |
} | ||
return PyUnicode_CompareWithASCIIString(expr->v.Name.id, "exit") == 0 || | ||
PyUnicode_CompareWithASCIIString(expr->v.Name.id, "quit") == 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests of the object associated with the names is needed to not turn them into semi-keywords, as in the the following.
>>> exit = 3
>>> exit
f:\dev\3x>
This PR is stale because it has been open for 30 days with no activity. |
@pablogsal this PR looks great, any chance you will continue working on it? :) |
There is still no agreement on the solution. Furthermore we are working on a new REPL for CPython that won't need this hack so probably that's the better rule if we decide to go that way |
Superseded by the work in #111201 |
https://bugs.python.org/issue44603