[IPython-dev] Splitting input by AST nodes

Thomas Kluyver takowl at gmail.com
Sun Apr 3 11:39:55 EDT 2011

On 3 April 2011 07:55, Fernando Perez <fperez.net at gmail.com> wrote:

> This is a great idea in principle, but as Brian points out, the issue
> is the extended ipython syntax.  As you can see in inputsplitter, the
> split_blocks method works by calling the .push() method, and the
> IPythonInputSplitter subclass overrides this method to extend what is
> considered valid syntax, by transforming things out.

My approach to this would be simply to transform input lines as they arrive
into valid Python syntax, then parse that to an AST. In fact, we already do
this - but then we use the linenos of the AST nodes to split the code string
up into blocks (which is what goes wrong in #306).

To what extent is the contract set in stone? E.g. I don't think I can easily
preserve the "if last block is two lines or less, run it interactively,
otherwise, just run it in exec mode" behaviour. But I remember this was
mentioned at Sage days, and someone put forward the suggestion that it would
be more consistent to always run the last block interactively (which is
probably what I'll implement).

I'll have a go at making this work.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20110403/ea762644/attachment.html>

More information about the IPython-dev mailing list