[IPython-dev] IPythonInputSplitter.cell_magic_parts and InteractiveShell

Jason Grout jason-sage at creativetrax.com
Wed Jun 20 09:55:53 EDT 2012

On 6/19/12 11:58 PM, MinRK wrote:
> On Tue, Jun 19, 2012 at 9:54 PM, Jason Grout
> <jason-sage at creativetrax.com <mailto:jason-sage at creativetrax.com>> wrote:
>     I'm working on getting the 0.13beta1 to work with Sage.  One problem is
>     that the InteractiveShell code assumes that the input splitter has a
>     .cell_magic_parts attribute (see line 2559 of
>     IPython/core/interactiveshell.py).  Now, this is not an attribute of
>     InputSplitter, but is an attribute of IPythonInputSplitter.  Do we have
>     to depend on having this attribute, or should InteractiveShell first
>     check for the existence of this attribute?  In Sage, we have our own
>     SageInputSplitter which inherits directly from InputSplitter, and so we
>     don't have the .cell_magic_parts attribute.
>     In other words, how decoupled do you want InteractiveShell and the
>     IPythonInputSplitter subclass of InputSplitter?
> I think we can just set InputSplitter.cell_magic_parts = None, so that
> it's clearly defined as an unused part of the public input splitter api.

That seems odd since InputSplitter doesn't do anything else with cell 
magics, right?  But if this is the way to go, it would be great if there 
was documentation (in your huge amount of spare time :) about what 
should go into that variable (seeing how we also have something like 
cell magics that would be interesting to see if we could now push into 
your system).

> or we use getattr in InteractiveShell, but I think we generally try to
> avoid that.

It seems like there should be a better solution, unless InputSplitter 
really will have cell magic features.  Maybe some sort of method in 
InputSplitter that creates a cell, instead of having InteractiveShell 
reach into the class to a variable to create a cell's code? 
IPythonSplitter would override the method to deal with cell magics, but 
it could be pretty straightforward in the InputSplitter class. 
Admittedly, I haven't looked very closely at exactly what happens to the 
cell_magic_parts variable, so I don't know if this is a real solution.



More information about the IPython-dev mailing list