Closed LilithHafner closed 8 months ago
Having played around with various combinations of whitespace, this issue only occurs if there is a newline followed by any other character after the expression.
julia> m = Py(Main)
Python: Julia: Main
julia> m.seval("1")
Python: 1
julia> m.seval("1 ")
Python: 1
julia> m.seval("1 ")
Python: 1
julia> m.seval("1\n")
Python: 1
julia> m.seval("1\n ")
ERROR: Python: Julia: Base.Meta.ParseError("extra token after end of expression")
The documentation for Meta.parse
says "An error is thrown if there are additional characters after the first expression." Presumably any whitespace before and any whitespace after up to a newline is being treated as part of the expression - which I suppose makes sense because newlines delimit expressions in Julia, but other whitespace does not.
Affects: JuliaCall
The issue is that Python's multiline string parsing is different from Julia's and does not strip trailing spaces as much, so the strict behavior of Julia's
Meta.parse
does not make sense for strings that were written using Python's multiline string syntax.I think PyCall doesn't have this issue, but I'm not positive.
I think that a good solution would be to strip inputs before parsing. It's hard to imagine a case when someone would want code with a leading or trailing space to throw a parse error.