-
-
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
Allow multiple statements in code.InteractiveConsole.push #51989
Comments
|
The code.InteractiveConsole() is useful to emulate a python console. However, any code currently "push"ed to it must be single statements. This is because it passes the ´single´ symbol mode to the underlying compile function. |
|
Note, there are no regression tests for the code module. |
|
Here is how to test this manually: |
|
Please can you starts a small test suite for the code module that tests the fix you are proposing and include it as another patch? |
|
Patch option 1 of 2. Incorporates Kristjan's patch and adds unit tests. This has the side effect of changing InteractiveConsole's behaviour with respect to displayhook(). I'm unsure if this is desirable. |
|
Patch option 2 of 2. Alternative patch that adds a new method to InteractiveConsole to split the string into multiple lines, feeding each line to interpreter using push(). This doesn't change the behaviour regarding the displayhook. But this may not meet Kristjan's original goals. |
|
A quick note regarding the last two patches submitted. These patches add unit tests using the test suite added for Issue bpo-12643. This limits the patches suitable to Python 3.3 and up. |
|
What's the purpose of the new patch, particularly 2/2 since it is equivalent to multiple push() calls? |
|
Aaron was looking for something to work on for the PyConAU sprints, and set himself the task of closing as many issues related to the code module as possible. The main outcome of that was the new test suite added in bpo-12643, which should make it easier to work on the module (at least in 3.3+) |
|
I agree that the second patch adds little value to InteractiveConsole. A third alternative would be to accept default grammar start symbol to be passed to __init__(). Although this would prevent mixing use of 'single' with 'exec'. |
|
OK, after a long detour that delved deep into codeop and the vagaries of PyCF_DONT_IMPLY_DEDENT (due to a problem that turned out to be due to a missing "\n" in a test case I added), my main conclusion is: Coupling the "single vs multiple statement" decision to the "implicit print after every call" decision is *really* annoying. The latter should be its own flag *or else* also implied by the "DONT_IMPLY_DEDENT" flag that is already passed to the compiler by codeop. If *that* gets fixed, then the code module could simply switch over to compiling in exec mode always, without any side effects on the implicit display of expression results. |
|
Should a new issue be created to decouple "print after every call" from the On Sunday, 9 December 2012, Nick Coghlan wrote:
|
|
More implicit magic seems like a bad idea, so I've split out a proposal for an explicit PyCF_DISPLAY_EXPRESSION_RESULTS flag as bpo-16649. The behaviour would then be selectable regardless of the compilation mode, but would remain the default for "single". |
|
Sounds fine. |
|
Good to know - I guess in most circumstances copy-and-paste already works, because the input will be arriving via a line-buffered IO stream. I was thinking that with bpo-16649 implemented, it would be possible to simply switch from "single" to "exec", without users needing to request the multi-statement support explicitly. However, I'm now back to wondering if such a change might have a few unforeseen consequences I haven't thought of. So if that seems like too much of a risk to backwards compatibility, how about moving the "symbol" argument to __init__, rather than needing to supply it with each call to push? |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: