Open nvcleemp opened 6 years ago
What else does the Sage preparser do and assume? Doesn't it turn all ints into (Sage) Integers, etc? Is any of this functionality needed?
Also Sage uses "^" for exponentiation. Will changing every occurrence to "**", solve this?
What else?
You can check what the preparser does to some specific code by running the preparse
function on a string.
sage: preparse("[0..12]")
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
More information is available here: http://doc.sagemath.org/html/en/reference/repl/sage/repl/preparse.html
My current approach is as follows:
graphs.sage
)
sage: from sage.repl.preparse import preparse_file
sage: s = preparse_file(open("src/Objects/graphs.sage", "r").read(), numeric_literals=False)
sage: open("src/Objects/graphs.py", "w").write(s)
Integer(*)
to *
. In a Unix-like environment this can be done with sed:
$ sed -i -E "s/Integer\(([0-9]*)\)/\1/g" src/Objects/graphs.py
RealNumber
:
$ sed -i -E "s/RealNumber\('([0-9.]*)'\)/\1/g" src/Objects/graphs.py
All code has been updated so that gt.sage
file now no longer has syntax errors when considered as a Python file. The file is not yet fully switched to Python code. There is a lot of code which still relies on the fact that the file is preparsed by Sage. E.g., 1/3 will give 0 in Python 2.7, but when preparsed by Sage will give the rational number 1/3.
Currently our code only works after it is processed by the Sage preparser. This means there are no linters available to do some code checks. Since the chances are only cosmetic, we should try to switch Python code everywhere. E.g., write
range(13)
instead of[0..12]
. This will help for #543.