classification
Title: Allow multiple statements in code.InteractiveConsole.push
Type: enhancement Stage: test needed
Components: Library (Lib) Versions: Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: cjw296, eric.araujo, krisvale
Priority: normal Keywords: needs review, patch

Created on 2010-01-19 14:52 by krisvale, last changed 2010-08-16 17:50 by eric.araujo.

Files
File name Uploaded Description Edit
code.patch krisvale, 2010-01-19 14:51 patch to code.py review
Messages (4)
msg98056 - (view) Author: Kristján Valur Jónsson (krisvale) * Date: 2010-01-19 14:51
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.
This patch allows the caller of InteractiveConsole.push to specify a different mode, e.g. ´exec´.  This is useful if one wants to paste entire code snippets into the console.  Without it, pasting the following:
'if True:\n  print 1\nprint 2' Won't run.  pushing such multiline code snippets with an additional 'exec' argument will allow it to work.
Patch included.
msg98057 - (view) Author: Kristján Valur Jónsson (krisvale) * Date: 2010-01-19 15:06
Note, there are no regression tests for the code module.
msg98058 - (view) Author: Kristján Valur Jónsson (krisvale) * Date: 2010-01-19 15:09
Here is how to test this manually:
from code import InteractiveConsole
c = InteractiveConsole()
s = "if True:\n  print 1\nprint 2"
c.push(s)  #fails
c.push(s, "exec")  #succeeds
msg98182 - (view) Author: Chris Withers (cjw296) * (Python committer) Date: 2010-01-23 12:24
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?
History
Date User Action Args
2010-08-16 17:50:37eric.araujosetnosy: + eric.araujo
2010-01-23 12:24:09cjw296setnosy: + cjw296
messages: + msg98182
2010-01-19 15:09:06krisvalesetmessages: + msg98058
2010-01-19 15:06:34krisvalesetmessages: + msg98057
2010-01-19 14:58:57brian.curtinsetpriority: normal
keywords: + needs review
stage: test needed
2010-01-19 14:52:01krisvalecreate