JuliaPy / PythonCall.jl

Python and Julia in harmony.
https://juliapy.github.io/PythonCall.jl/stable/
MIT License
721 stars 61 forks source link

Better error message on `pyexec(Main, "1+1")` #383

Closed LilithHafner closed 8 months ago

LilithHafner commented 8 months ago
julia> pyexec(Main, "1+1")
ERROR: UndefVarError: `globals_` not defined
Stacktrace:
 [1] _pyeval_args(globals::String, locals::Nothing)
   @ PythonCall ~/.julia/packages/PythonCall/qTEA1/src/concrete/code.jl:12
 [2] pyexec(::Type{Nothing}, code::Module, globals::String, locals::Nothing)
   @ PythonCall ~/.julia/packages/PythonCall/qTEA1/src/concrete/code.jl:97
 [3] pyexec(code::Module, globals::String, locals::Nothing)
   @ PythonCall ~/.julia/packages/PythonCall/qTEA1/src/concrete/code.jl:103
 [4] pyexec(code::Module, globals::String)
   @ PythonCall ~/.julia/packages/PythonCall/qTEA1/src/concrete/code.jl:103
 [5] top-level scope
   @ REPL[8]:1

I think this should probably be a method error.

cjdoris commented 8 months ago

https://github.com/JuliaPy/PythonCall.jl/blob/16c23749dcc26e5cfa17b44c823fd1cfffb44af6/src/concrete/code.jl#L9 is missing a throw(...)!