-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Improve parser to accept complicated block of code under interactive REPL #111658
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
Comments
This is not a minor feature. Terminating multiple-logical-line compound statements with a blank line is a core feature of interactive mode. Properly formatted 'interactive' code with blank lines after all such statements and never within such statements can be pasted today in the REPL. First physical lines of such statements will be marked with a primary prompt and and subsequent lines with secondary prompts. Output for a statement will appear after the statement and before the next statement. Blank lines tell the interpreter to execute the statement and then send a new primary prompt to the terminal before it displays another statement. |
@terryjreedy Thanks for your reply. My current implementation seems flawed and I would correct it later, but before this I would like to clarify the desired effect of this proposal:
I was wondering whether this proposal would be accepted given the behavior described above? |
@pablogsal is working on the REPL in #111201, so this feature would have to build on that work, if it's not already included there (I haven't been following it very closely). |
Yeah, the parser is not the correct way to fix this IMHO, the repl is. Currently, unfortunately both are tangled but after the work in #111201 they won't be so we can have a better place to include this behavior and make it easier to address the underlying problem which seems to allow users to paste code. |
This is fixed by PyREPL's introduction. |
Feature or enhancement
Proposal:
Previously the Python REPL only accepts either a single compound statement or a line of simple statements. For example, we can either do:
or do:
However, the REPL doesn't accept multiple consecutive compound statements, or any simple statement followed soon after a compound statement:
This will cause a lot of frustration when, for example, a user pastes snippet directly into the REPL and sees unexpected syntax error.
Hence, I propose to improve the parser, specifically the
statement_newline
rule to accept the abovementioned cases.Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
The text was updated successfully, but these errors were encountered: