How do i turn a PyNone into a Bound<PyAny>? #4021
-
Im trying to unwrap my locals, and while i could theoretically just call unwrap since its test code, i would like to know how to do this kind of thing in case i need to for shipped code. im not very new to rust, but have no idea what im doing:
full disclosure is im working on pydantic core tests, here are some more details on what im doing and seeing: #[test]
fn test() {
Python::with_gil(|py| {
let locals = PyDict::new_bound(py);
// py.import_bound(r"pydantic_core").unwrap();
// py.run_bound(r"
// from pydantic import BaseModel
// abc = BaseModel
// ", None, Some(&locals)).unwrap();
let abc = locals.get_item(r"abc").unwrap_or(Option::None).unwrap_or(PyNone::get_bound(py));
println!("{:#?}", abc);
})
}
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I think PyNone::get_bound(py).to_owned().into_any() |
Beta Was this translation helpful? Give feedback.
-
You could do: py.None().into_bound(py) |
Beta Was this translation helpful? Give feedback.
You could do: