From 2ab8b23dd67295fb3ab8a1348c06535bc8040f33 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 6 Apr 2024 09:29:37 -0400 Subject: [PATCH] Convert `src/types.rs` to new pyo3 APIs (#10754) --- src/rust/src/types.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rust/src/types.rs b/src/rust/src/types.rs index c3590948b..6200801be 100644 --- a/src/rust/src/types.rs +++ b/src/rust/src/types.rs @@ -2,6 +2,8 @@ // 2.0, and the BSD License. See the LICENSE file in the root of this repository // for complete details. +use pyo3::prelude::PyAnyMethods; + pub struct LazyPyImport { module: &'static str, names: &'static [&'static str], @@ -26,11 +28,11 @@ impl LazyPyImport { py: pyo3::Python<'p>, ) -> pyo3::PyResult> { let p = self.value.get_or_try_init(py, || { - let mut obj = py.import(self.module)?.as_ref(); + let mut obj = py.import_bound(self.module)?.into_any(); for name in self.names { obj = obj.getattr(*name)?; } - obj.extract() + Ok::<_, pyo3::PyErr>(obj.unbind()) })?; Ok(p.clone().into_bound(py))