Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I assume you're using load("..."). As you can see from the traceback, python is registering where it got its source from: "<string>". Ipython just doesn't know how to get line numbers for that, or how to display the string (probably because it has been forgotten). This is the standard behaviour of python's "exec":

Python 2.7.10 (default, Sep 24 2015, 17:50:09) 
[GCC 5.1.1 20150618 (Red Hat 5.1.1-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exec "def f(): raise RuntimeError\n"
>>> f()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1, in f

(there does seem to be line information here, but the <string> file suggests there's nowhere to look this up)

On ipython's command line and its magic "%load" does store source information beyond a <string> directive.

sage: def f(): raise RuntimeError
sage: f()
RuntimeError                              Traceback (most recent call last)
<ipython-input-31-0ec059b9bfe1> in <module>()
----> 1 f()

<ipython-input-30-5041dc482b26> in f()
----> 1 def f(): raise RuntimeError

(note there's a traceback, and the source file is not just "<string>" but something that looks like a pointer into Ipython's command history)

Short version: as a workaround, you can try %load myfile.sage rather than load("myfile.sage").

In the longer run: someone could look into how Ipython stores source for loaded input and see if sage.repl.load.load can be adapted to make use of this. It might not be so easy: sage's load has to work more generally than just inside Ipython, and has to be efficient there as well. It may not be able to store source in all cases.