Closed lassepe closed 1 year ago
You want @pyexec
(for executing arbitrary python code) not @pyeval
(which evaluates a single expression):
julia> using PythonCall
julia> @pyeval `raise ValueError("hello")`
ERROR: Python: SyntaxError: invalid syntax (REPL[2]:1, line 1)
julia> @pyexec `raise ValueError("hello")`
ERROR: Python: ValueError: hello
Nice, this works like charm! Thank you :)
Some python package apis require the user the raise specific errors in certain scenarios. For example, Optuna requires the user to conditionally
TrialPruned()
error. In the current implementation of PythonCall, raising such errors from julia functions does not seem to be possible.fails with
Python: SyntaxError: invalid syntax
.It would be handy to have a function like
pyraise
to throw such errors manually.