Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main.seval can't parse multiple toplevel blocks #433

Closed
LilithHafner opened this issue Dec 6, 2023 · 3 comments · Fixed by #452
Closed

Main.seval can't parse multiple toplevel blocks #433

LilithHafner opened this issue Dec 6, 2023 · 3 comments · Fixed by #452
Labels
bug Something isn't working
Milestone

Comments

@LilithHafner
Copy link
Contributor

Affects: JuliaCall

>>> from juliacall import Main
>>> Main.seval("x = 1+1; println(x)")
2
>>> Main.seval("x = 1+1\n println(x)")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/x/.julia/packages/PythonCall/qTEA1/src/jlwrap/module.jl", line 25, in seval
    return self._jl_callmethod($(pyjl_methodnum(pyjlmodule_seval)), expr)
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
juliacall.JuliaError: Base.Meta.ParseError("extra token after end of expression")
Stacktrace:
 [1] parse(str::String; raise::Bool, depwarn::Bool)
   @ Base.Meta ./meta.jl:272
 [2] parse
   @ ./meta.jl:266 [inlined]
 [3] pyjlmodule_seval(self::Module, expr::Py)
   @ PythonCall ~/.julia/packages/PythonCall/qTEA1/src/jlwrap/module.jl:13
 [4] _pyjl_callmethod(f::Any, self_::Ptr{PythonCall.C.PyObject}, args_::Ptr{PythonCall.C.PyObject}, nargs::Int64)
   @ PythonCall ~/.julia/packages/PythonCall/qTEA1/src/jlwrap/base.jl:62
 [5] _pyjl_callmethod(o::Ptr{PythonCall.C.PyObject}, args::Ptr{PythonCall.C.PyObject})
   @ PythonCall.C ~/.julia/packages/PythonCall/qTEA1/src/cpython/jlwrap.jl:47

The issue here, I suspect, is that JuiliaCall uses a parsing method that accepts only a single top-level block. This is not ideal as Julia's eval ∘ Meta.parse accepts any number top-level expressions. What makes this a bug, though, is how subtle the difference between a single top-level block and multiple top-level blocks is. Specifically a; b is okay but a\nb is not which is very bad.

Fixing this may also fix #379 which would allow us to revert #380

@LilithHafner LilithHafner added the bug Something isn't working label Dec 6, 2023
@cjdoris
Copy link
Collaborator

cjdoris commented Jan 25, 2024

If we're being pedantic about it this isn't a bug: a;b really is a single block expression (this is the documented meaning of ;) whereas a\nb is just two expressions separated by whitespace, which don't become a single expression until wrapped in some higher block such as begin ... end.

Anyway I totally agree that seval should support multiple expressions.

@cjdoris cjdoris added this to the features milestone Jan 25, 2024
@MilesCranmer
Copy link
Contributor

Can I help add this? This is a blocker for MilesCranmer/PySR#535

@MilesCranmer
Copy link
Contributor

MilesCranmer commented Feb 8, 2024

Ah it looks like the fix is just Meta.parse -> Meta.parseall.

Edit: fixed in #452

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants