Cannot convert int to sage.rings.integer.Integer
I created a minimal example in the file bad.py
from sage.all import *
j = 0
m = matrix(3,3)
m.insert_row(j, [1,1,1])
Then from sage:
sage: load bad.py
TypeError: Cannot convert int to sage.rings.integer.Integer
I think I can see an easy workaround, I can wrap all the 1's in Integer() (or change the name of the file to .sage so the preparser does it), but why is that necessary? Is this a bug? Why would sage not be able to convert int to Integer? Isn't that a pretty obvious conversion?
It's important to have a way of using Python types like int without having the preparser rewrite them, that's why the load and attach behavior of `.py` files and `.sage` files is different. But, I agree, it should be trivial for the matrix code to coerce `int` to `Integer`. It could be that the coercion is not done for a specific reason. I'm also curious why if you declare `m = matrix(QQ, 3, 3)` that `m` no longer has an `insert_row` method.
Yeah, insert_row seems to only be defined for dense integer matrices - check out sage: search_def('insert_row'). Presumably at least some of this could be recycled. Sounds like another Trac ticket to file! Or search for.