I'm playing with replacing our `native.py` `Extern...
# development
h
I'm playing with replacing our
native.py
Externs.create_exception()
method with instead using CPython's
eval(code: &str)
mechanism, which will reduce FFI boilerplate. But I'm stuck on escaping of quotes. I'm writing
py.eval(&format!("Exception(\"{}\")", msg)
, and it results in a syntax error if
msg
has
"
in it. We need to modify
msg
so that
"
is transformed into
\"
. I'm not finding a good way to do this in Rust - the best I've thought of is to map over
.chars()
and create a new
String
?
f
Copy code
Example: return Err(PyErr::new::<exc::TypeError, _>(py, "Error message"));
h
We need the wrapping
Exception()
for the sake of generating a string But the above problem is solved by using
PyModule.call()
instead of
eval()
. Yay!