From b520bc1704eb92f77188b49b356dfc29fc5fa42a Mon Sep 17 00:00:00 2001 From: Icxolu <10486322+Icxolu@users.noreply.github.com> Date: Mon, 12 Aug 2024 23:57:36 +0200 Subject: [PATCH] Reintroduces `Python::import` and `Python::get_type` (#4436) * reintroduce `Python::import` * reintroduce `Python::get_type` --- README.md | 4 +-- guide/src/class.md | 26 +++++++++---------- guide/src/exception.md | 4 +-- guide/src/migration.md | 6 ++--- .../python-from-rust/calling-existing-code.md | 4 +-- pyo3-macros-backend/src/pyclass.rs | 2 +- src/buffer.rs | 2 +- src/conversions/chrono.rs | 10 +++---- src/conversions/chrono_tz.rs | 5 +--- src/conversions/num_bigint.rs | 4 +-- src/conversions/std/time.rs | 14 +++------- src/coroutine/waker.rs | 2 +- src/err/mod.rs | 6 ++--- src/exceptions.rs | 20 +++++++------- src/gil.rs | 2 +- src/impl_/extract_argument.rs | 5 +--- src/impl_/pymodule.rs | 6 ++--- src/instance.rs | 4 +-- src/lib.rs | 4 +-- src/macros.rs | 2 +- src/marker.rs | 26 +++++++++++++++++-- src/pyclass_init.rs | 2 +- src/sync.rs | 2 +- src/tests/common.rs | 8 +++--- src/types/any.rs | 12 ++++----- src/types/dict.rs | 8 +++--- src/types/string.rs | 6 ++--- src/types/traceback.rs | 2 +- src/types/typeobject.rs | 25 ++++++++---------- tests/test_class_attributes.rs | 20 +++++++------- tests/test_class_basics.rs | 16 ++++++------ tests/test_class_new.rs | 22 ++++++++-------- tests/test_coroutine.rs | 12 ++++----- tests/test_datetime.rs | 2 +- tests/test_datetime_import.rs | 2 +- tests/test_enum.rs | 14 +++++----- tests/test_gc.rs | 16 ++++++------ tests/test_getter_setter.rs | 2 +- tests/test_inheritance.rs | 14 +++++----- tests/test_macro_docs.rs | 2 +- tests/test_macros.rs | 4 +-- tests/test_mapping.rs | 2 +- tests/test_methods.rs | 14 +++++----- tests/test_multiple_pymethods.rs | 2 +- tests/test_proto_methods.rs | 8 +++--- tests/test_sequence.rs | 6 ++--- tests/test_static_slots.rs | 2 +- tests/test_super.rs | 2 +- tests/test_text_signature.rs | 16 ++++++------ tests/test_variable_arguments.rs | 4 +-- tests/ui/invalid_intern_arg.rs | 2 +- tests/ui/invalid_intern_arg.stderr | 16 ++++++------ 52 files changed, 215 insertions(+), 208 deletions(-) diff --git a/README.md b/README.md index 908f184cc6b..d0c53f0d86c 100644 --- a/README.md +++ b/README.md @@ -149,10 +149,10 @@ use pyo3::types::IntoPyDict; fn main() -> PyResult<()> { Python::with_gil(|py| { - let sys = py.import_bound("sys")?; + let sys = py.import("sys")?; let version: String = sys.getattr("version")?.extract()?; - let locals = [("os", py.import_bound("os")?)].into_py_dict(py); + let locals = [("os", py.import("os")?)].into_py_dict(py); let code = "os.getenv('USER') or os.getenv('USERNAME') or 'Unknown'"; let user: String = py.eval_bound(code, None, Some(&locals))?.extract()?; diff --git a/guide/src/class.md b/guide/src/class.md index 216838f779d..9f87f2828b0 100644 --- a/guide/src/class.md +++ b/guide/src/class.md @@ -430,7 +430,7 @@ impl SubSubClass { # pyo3::py_run!(py, subsub, "assert subsub.get_values() == (20, 30, 40)"); # let subsub = SubSubClass::factory_method(py, 2).unwrap(); # let subsubsub = SubSubClass::factory_method(py, 3).unwrap(); -# let cls = py.get_type_bound::(); +# let cls = py.get_type::(); # pyo3::py_run!(py, subsub cls, "assert not isinstance(subsub, cls)"); # pyo3::py_run!(py, subsubsub cls, "assert isinstance(subsubsub, cls)"); # }); @@ -526,7 +526,7 @@ impl MyDict { // some custom methods that use `private` here... } # Python::with_gil(|py| { -# let cls = py.get_type_bound::(); +# let cls = py.get_type::(); # pyo3::py_run!(py, cls, "cls(a=1, b=2)") # }); # } @@ -797,7 +797,7 @@ impl MyClass { } Python::with_gil(|py| { - let my_class = py.get_type_bound::(); + let my_class = py.get_type::(); pyo3::py_run!(py, my_class, "assert my_class.my_attribute == 'hello'") }); ``` @@ -1093,7 +1093,7 @@ enum MyEnum { Python::with_gil(|py| { let x = Py::new(py, MyEnum::Variant).unwrap(); let y = Py::new(py, MyEnum::OtherVariant).unwrap(); - let cls = py.get_type_bound::(); + let cls = py.get_type::(); pyo3::py_run!(py, x y cls, r#" assert x == cls.Variant assert y == cls.OtherVariant @@ -1114,7 +1114,7 @@ enum MyEnum { } Python::with_gil(|py| { - let cls = py.get_type_bound::(); + let cls = py.get_type::(); let x = MyEnum::Variant as i32; // The exact value is assigned by the compiler. pyo3::py_run!(py, cls x, r#" assert int(cls.Variant) == x @@ -1135,7 +1135,7 @@ enum MyEnum{ } Python::with_gil(|py| { - let cls = py.get_type_bound::(); + let cls = py.get_type::(); let x = Py::new(py, MyEnum::Variant).unwrap(); pyo3::py_run!(py, cls x, r#" assert repr(x) == 'MyEnum.Variant' @@ -1162,7 +1162,7 @@ impl MyEnum { } Python::with_gil(|py| { - let cls = py.get_type_bound::(); + let cls = py.get_type::(); pyo3::py_run!(py, cls, "assert repr(cls.Answer) == '42'") }) ``` @@ -1180,7 +1180,7 @@ enum MyEnum { Python::with_gil(|py| { let x = Py::new(py, MyEnum::Variant).unwrap(); - let cls = py.get_type_bound::(); + let cls = py.get_type::(); pyo3::py_run!(py, x cls, r#" assert repr(x) == 'RenamedEnum.UPPERCASE' assert x == cls.UPPERCASE @@ -1202,7 +1202,7 @@ enum MyEnum{ } Python::with_gil(|py| { - let cls = py.get_type_bound::(); + let cls = py.get_type::(); let a = Py::new(py, MyEnum::A).unwrap(); let b = Py::new(py, MyEnum::B).unwrap(); let c = Py::new(py, MyEnum::C).unwrap(); @@ -1260,7 +1260,7 @@ enum Shape { Python::with_gil(|py| { let circle = Shape::Circle { radius: 10.0 }.into_py(py); let square = Shape::RegularPolygon(4, 10.0).into_py(py); - let cls = py.get_type_bound::(); + let cls = py.get_type::(); pyo3::py_run!(py, circle square cls, r#" assert isinstance(circle, cls) assert isinstance(circle, cls.Circle) @@ -1299,7 +1299,7 @@ enum MyEnum { Python::with_gil(|py| { let x = Py::new(py, MyEnum::Variant { i: 42 }).unwrap(); - let cls = py.get_type_bound::(); + let cls = py.get_type::(); pyo3::py_run!(py, x cls, r#" assert isinstance(x, cls) assert not isinstance(x, cls.Variant) @@ -1325,7 +1325,7 @@ enum Shape { # #[cfg(Py_3_10)] Python::with_gil(|py| { - let cls = py.get_type_bound::(); + let cls = py.get_type::(); pyo3::py_run!(py, cls, r#" circle = cls.Circle() assert isinstance(circle, cls) @@ -1446,7 +1446,7 @@ impl pyo3::impl_::pyclass::PyClassImpl for MyClass { } # Python::with_gil(|py| { -# let cls = py.get_type_bound::(); +# let cls = py.get_type::(); # pyo3::py_run!(py, cls, "assert cls.__name__ == 'MyClass'") # }); # } diff --git a/guide/src/exception.md b/guide/src/exception.md index 0235614f6ea..32a56078af5 100644 --- a/guide/src/exception.md +++ b/guide/src/exception.md @@ -24,7 +24,7 @@ use pyo3::exceptions::PyException; create_exception!(mymodule, CustomError, PyException); Python::with_gil(|py| { - let ctx = [("CustomError", py.get_type_bound::())].into_py_dict(py); + let ctx = [("CustomError", py.get_type::())].into_py_dict(py); pyo3::py_run!( py, *ctx, @@ -46,7 +46,7 @@ pyo3::create_exception!(mymodule, CustomError, PyException); #[pymodule] fn mymodule(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> { // ... other elements added to module ... - m.add("CustomError", py.get_type_bound::())?; + m.add("CustomError", py.get_type::())?; Ok(()) } diff --git a/guide/src/migration.md b/guide/src/migration.md index c55900651d5..1abb7202e4d 100644 --- a/guide/src/migration.md +++ b/guide/src/migration.md @@ -214,7 +214,7 @@ Python::with_gil(|py| { After: -```rust +```rust,ignore # #![allow(dead_code)] # use pyo3::prelude::*; # use pyo3::types::{PyBool}; @@ -593,7 +593,7 @@ assert_eq!(name, "list"); After: -```rust +```rust,ignore # #[cfg(any(not(Py_LIMITED_API), Py_3_10))] { # use pyo3::prelude::*; # use pyo3::types::{PyList, PyType}; @@ -614,7 +614,7 @@ To avoid needing to worry about lifetimes at all, it is also possible to use the The following example uses the same snippet as those just above, but this time the final extracted type is `PyBackedStr`: -```rust +```rust,ignore # use pyo3::prelude::*; # use pyo3::types::{PyList, PyType}; # fn example<'py>(py: Python<'py>) -> PyResult<()> { diff --git a/guide/src/python-from-rust/calling-existing-code.md b/guide/src/python-from-rust/calling-existing-code.md index dd4a28458ed..997009310b4 100644 --- a/guide/src/python-from-rust/calling-existing-code.md +++ b/guide/src/python-from-rust/calling-existing-code.md @@ -291,7 +291,7 @@ fn main() -> PyResult<()> { let py_app = fs::read_to_string(path.join("app.py"))?; let from_python = Python::with_gil(|py| -> PyResult> { let syspath = py - .import_bound("sys")? + .import("sys")? .getattr("path")? .downcast_into::()?; syspath.insert(0, &path)?; @@ -383,7 +383,7 @@ use pyo3::prelude::*; # fn main() -> PyResult<()> { Python::with_gil(|py| -> PyResult<()> { - let signal = py.import_bound("signal")?; + let signal = py.import("signal")?; // Set SIGINT to have the default action signal .getattr("signal")? diff --git a/pyo3-macros-backend/src/pyclass.rs b/pyo3-macros-backend/src/pyclass.rs index 50c123a90fb..164b5f7e921 100644 --- a/pyo3-macros-backend/src/pyclass.rs +++ b/pyo3-macros-backend/src/pyclass.rs @@ -1535,7 +1535,7 @@ pub fn gen_complex_enum_variant_attr( let variant_cls = format_ident!("{}_{}", cls, member); let associated_method = quote! { fn #wrapper_ident(py: #pyo3_path::Python<'_>) -> #pyo3_path::PyResult<#pyo3_path::PyObject> { - ::std::result::Result::Ok(py.get_type_bound::<#variant_cls>().into_any().unbind()) + ::std::result::Result::Ok(py.get_type::<#variant_cls>().into_any().unbind()) } }; diff --git a/src/buffer.rs b/src/buffer.rs index 2a6d602d567..f2e402aecd4 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -880,7 +880,7 @@ mod tests { fn test_array_buffer() { Python::with_gil(|py| { let array = py - .import_bound("array") + .import("array") .unwrap() .call_method("array", ("f", (1.0, 1.5, 2.0, 2.5)), None) .unwrap(); diff --git a/src/conversions/chrono.rs b/src/conversions/chrono.rs index 1da39cdb32b..47c22f0c18f 100644 --- a/src/conversions/chrono.rs +++ b/src/conversions/chrono.rs @@ -678,7 +678,7 @@ fn warn_truncated_leap_second(obj: &Bound<'_, PyAny>) { let py = obj.py(); if let Err(e) = PyErr::warn_bound( py, - &py.get_type_bound::(), + &py.get_type::(), "ignored leap-second, `datetime` does not support leap-seconds", 0, ) { @@ -762,7 +762,7 @@ impl DatetimeTypes { fn try_get(py: Python<'_>) -> PyResult<&Self> { static TYPES: GILOnceCell = GILOnceCell::new(); TYPES.get_or_try_init(py, || { - let datetime = py.import_bound("datetime")?; + let datetime = py.import("datetime")?; let timezone = datetime.getattr("timezone")?; Ok::<_, PyErr>(Self { date: datetime.getattr("date")?.into(), @@ -1297,7 +1297,7 @@ mod tests { name: &str, args: impl IntoPy>, ) -> Bound<'py, PyAny> { - py.import_bound("datetime") + py.import("datetime") .unwrap() .getattr(name) .unwrap() @@ -1306,7 +1306,7 @@ mod tests { } fn python_utc(py: Python<'_>) -> Bound<'_, PyAny> { - py.import_bound("datetime") + py.import("datetime") .unwrap() .getattr("timezone") .unwrap() @@ -1328,7 +1328,7 @@ mod tests { fn test_pyo3_offset_fixed_frompyobject_created_in_python(timestamp in 0..(i32::MAX as i64), timedelta in -86399i32..=86399i32) { Python::with_gil(|py| { - let globals = [("datetime", py.import_bound("datetime").unwrap())].into_py_dict(py); + let globals = [("datetime", py.import("datetime").unwrap())].into_py_dict(py); let code = format!("datetime.datetime.fromtimestamp({}).replace(tzinfo=datetime.timezone(datetime.timedelta(seconds={})))", timestamp, timedelta); let t = py.eval_bound(&code, Some(&globals), None).unwrap(); diff --git a/src/conversions/chrono_tz.rs b/src/conversions/chrono_tz.rs index 1b5e3cd95f7..88bf39de64a 100644 --- a/src/conversions/chrono_tz.rs +++ b/src/conversions/chrono_tz.rs @@ -128,9 +128,6 @@ mod tests { } fn zoneinfo_class(py: Python<'_>) -> Bound<'_, PyAny> { - py.import_bound("zoneinfo") - .unwrap() - .getattr("ZoneInfo") - .unwrap() + py.import("zoneinfo").unwrap().getattr("ZoneInfo").unwrap() } } diff --git a/src/conversions/num_bigint.rs b/src/conversions/num_bigint.rs index 74322bde482..d709824d702 100644 --- a/src/conversions/num_bigint.rs +++ b/src/conversions/num_bigint.rs @@ -121,7 +121,7 @@ macro_rules! bigint_conversion { } else { None }; - py.get_type_bound::() + py.get_type::() .call_method("from_bytes", (bytes_obj, "little"), kwargs.as_ref()) .expect("int.from_bytes() failed during to_object()") // FIXME: #1813 or similar .into() @@ -170,7 +170,7 @@ macro_rules! bigint_conversion { None }; unsafe { - py.get_type_bound::() + py.get_type::() .call_method("from_bytes", (bytes_obj, "little"), kwargs.as_ref()) .downcast_into_unchecked() } diff --git a/src/conversions/std/time.rs b/src/conversions/std/time.rs index 31d7f965883..4c5c56e4cac 100755 --- a/src/conversions/std/time.rs +++ b/src/conversions/std/time.rs @@ -194,7 +194,7 @@ fn unix_epoch_py(py: Python<'_>) -> &PyObject { } #[cfg(Py_LIMITED_API)] { - let datetime = py.import_bound("datetime")?; + let datetime = py.import("datetime")?; let utc = datetime.getattr("timezone")?.getattr("utc")?; Ok::<_, PyErr>( datetime @@ -412,7 +412,7 @@ mod tests { } fn tz_utc(py: Python<'_>) -> Bound<'_, PyAny> { - py.import_bound("datetime") + py.import("datetime") .unwrap() .getattr("timezone") .unwrap() @@ -432,16 +432,10 @@ mod tests { } fn datetime_class(py: Python<'_>) -> Bound<'_, PyAny> { - py.import_bound("datetime") - .unwrap() - .getattr("datetime") - .unwrap() + py.import("datetime").unwrap().getattr("datetime").unwrap() } fn timedelta_class(py: Python<'_>) -> Bound<'_, PyAny> { - py.import_bound("datetime") - .unwrap() - .getattr("timedelta") - .unwrap() + py.import("datetime").unwrap().getattr("timedelta").unwrap() } } diff --git a/src/coroutine/waker.rs b/src/coroutine/waker.rs index bb93974aa1e..1600f56d9c6 100644 --- a/src/coroutine/waker.rs +++ b/src/coroutine/waker.rs @@ -60,7 +60,7 @@ impl LoopAndFuture { fn new(py: Python<'_>) -> PyResult { static GET_RUNNING_LOOP: GILOnceCell = GILOnceCell::new(); let import = || -> PyResult<_> { - let module = py.import_bound("asyncio")?; + let module = py.import("asyncio")?; Ok(module.getattr("get_running_loop")?.into()) }; let event_loop = GET_RUNNING_LOOP.get_or_try_init(py, import)?.call0(py)?; diff --git a/src/err/mod.rs b/src/err/mod.rs index 3e344c4a66f..6e1e00844d8 100644 --- a/src/err/mod.rs +++ b/src/err/mod.rs @@ -596,7 +596,7 @@ impl PyErr { /// # use pyo3::prelude::*; /// # fn main() -> PyResult<()> { /// Python::with_gil(|py| { - /// let user_warning = py.get_type_bound::(); + /// let user_warning = py.get_type::(); /// PyErr::warn_bound(py, &user_warning, "I am warning you", 0)?; /// Ok(()) /// }) @@ -1125,10 +1125,10 @@ mod tests { // GIL locked should prevent effects to be visible to other testing // threads. Python::with_gil(|py| { - let cls = py.get_type_bound::(); + let cls = py.get_type::(); // Reset warning filter to default state - let warnings = py.import_bound("warnings").unwrap(); + let warnings = py.import("warnings").unwrap(); warnings.call_method0("resetwarnings").unwrap(); // First, test the warning is emitted diff --git a/src/exceptions.rs b/src/exceptions.rs index e2649edd08b..ee35e4752e1 100644 --- a/src/exceptions.rs +++ b/src/exceptions.rs @@ -62,7 +62,7 @@ macro_rules! impl_exception_boilerplate_bound { /// import_exception!(socket, gaierror); /// /// Python::with_gil(|py| { -/// let ctx = [("gaierror", py.get_type_bound::())].into_py_dict(py); +/// let ctx = [("gaierror", py.get_type::())].into_py_dict(py); /// pyo3::py_run!(py, *ctx, "import socket; assert gaierror is socket.gaierror"); /// }); /// @@ -168,7 +168,7 @@ macro_rules! import_exception_bound { /// /// #[pymodule] /// fn my_module(m: &Bound<'_, PyModule>) -> PyResult<()> { -/// m.add("MyError", m.py().get_type_bound::())?; +/// m.add("MyError", m.py().get_type::())?; /// m.add_function(wrap_pyfunction!(raise_myerror, m)?)?; /// Ok(()) /// } @@ -176,7 +176,7 @@ macro_rules! import_exception_bound { /// # Python::with_gil(|py| -> PyResult<()> { /// # let fun = wrap_pyfunction!(raise_myerror, py)?; /// # let locals = pyo3::types::PyDict::new(py); -/// # locals.set_item("MyError", py.get_type_bound::())?; +/// # locals.set_item("MyError", py.get_type::())?; /// # locals.set_item("raise_myerror", fun)?; /// # /// # py.run_bound( @@ -258,7 +258,7 @@ macro_rules! create_exception_type_object { py, concat!(stringify!($module), ".", stringify!($name)), $doc, - ::std::option::Option::Some(&py.get_type_bound::<$base>()), + ::std::option::Option::Some(&py.get_type::<$base>()), ::std::option::Option::None, ).expect("Failed to initialize new exception type.") ).as_ptr() as *mut $crate::ffi::PyTypeObject @@ -822,7 +822,7 @@ mod tests { Python::with_gil(|py| { let err: PyErr = gaierror::new_err(()); let socket = py - .import_bound("socket") + .import("socket") .map_err(|e| e.display(py)) .expect("could not import socket"); @@ -846,7 +846,7 @@ mod tests { Python::with_gil(|py| { let err: PyErr = MessageError::new_err(()); let email = py - .import_bound("email") + .import("email") .map_err(|e| e.display(py)) .expect("could not import email"); @@ -873,7 +873,7 @@ mod tests { create_exception!(mymodule, CustomError, PyException); Python::with_gil(|py| { - let error_type = py.get_type_bound::(); + let error_type = py.get_type::(); let ctx = [("CustomError", error_type)].into_py_dict(py); let type_description: String = py .eval_bound("str(CustomError)", None, Some(&ctx)) @@ -896,7 +896,7 @@ mod tests { fn custom_exception_dotted_module() { create_exception!(mymodule.exceptions, CustomError, PyException); Python::with_gil(|py| { - let error_type = py.get_type_bound::(); + let error_type = py.get_type::(); let ctx = [("CustomError", error_type)].into_py_dict(py); let type_description: String = py .eval_bound("str(CustomError)", None, Some(&ctx)) @@ -915,7 +915,7 @@ mod tests { create_exception!(mymodule, CustomError, PyException, "Some docs"); Python::with_gil(|py| { - let error_type = py.get_type_bound::(); + let error_type = py.get_type::(); let ctx = [("CustomError", error_type)].into_py_dict(py); let type_description: String = py .eval_bound("str(CustomError)", None, Some(&ctx)) @@ -948,7 +948,7 @@ mod tests { ); Python::with_gil(|py| { - let error_type = py.get_type_bound::(); + let error_type = py.get_type::(); let ctx = [("CustomError", error_type)].into_py_dict(py); let type_description: String = py .eval_bound("str(CustomError)", None, Some(&ctx)) diff --git a/src/gil.rs b/src/gil.rs index 644fbe6e00a..71b95e55b18 100644 --- a/src/gil.rs +++ b/src/gil.rs @@ -123,7 +123,7 @@ where let py = guard.python(); // Import the threading module - this ensures that it will associate this thread as the "main" // thread, which is important to avoid an `AssertionError` at finalization. - py.import_bound("threading").unwrap(); + py.import("threading").unwrap(); // Execute the closure. f(py) diff --git a/src/impl_/extract_argument.rs b/src/impl_/extract_argument.rs index 3466dc268ea..e2a184ce7dd 100644 --- a/src/impl_/extract_argument.rs +++ b/src/impl_/extract_argument.rs @@ -200,10 +200,7 @@ pub fn from_py_with_with_default<'a, 'py, T>( #[doc(hidden)] #[cold] pub fn argument_extraction_error(py: Python<'_>, arg_name: &str, error: PyErr) -> PyErr { - if error - .get_type_bound(py) - .is(&py.get_type_bound::()) - { + if error.get_type_bound(py).is(&py.get_type::()) { let remapped_error = PyTypeError::new_err(format!( "argument '{}': {}", arg_name, diff --git a/src/impl_/pymodule.rs b/src/impl_/pymodule.rs index 2cdb1bff8f8..08d55bfa5e8 100644 --- a/src/impl_/pymodule.rs +++ b/src/impl_/pymodule.rs @@ -92,11 +92,11 @@ impl ModuleDef { use crate::types::any::PyAnyMethods; const PYPY_GOOD_VERSION: [u8; 3] = [7, 3, 8]; let version = py - .import_bound("sys")? + .import("sys")? .getattr("implementation")? .getattr("version")?; if version.lt(crate::types::PyTuple::new(py, PYPY_GOOD_VERSION))? { - let warn = py.import_bound("warnings")?.getattr("warn")?; + let warn = py.import("warnings")?.getattr("warn")?; warn.call1(( "PyPy 3.7 versions older than 7.3.8 are known to have binary \ compatibility issues which may cause segfaults. Please upgrade.", @@ -286,7 +286,7 @@ mod tests { assert_eq!((*module_def.ffi_def.get()).m_doc, DOC.as_ptr() as _); Python::with_gil(|py| { - module_def.initializer.0(&py.import_bound("builtins").unwrap()).unwrap(); + module_def.initializer.0(&py.import("builtins").unwrap()).unwrap(); assert!(INIT_CALLED.load(Ordering::SeqCst)); }) } diff --git a/src/instance.rs b/src/instance.rs index 96b3f3e554c..773431859c9 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -1422,7 +1422,7 @@ impl Py { /// } /// # /// # Python::with_gil(|py| { - /// # let sys = py.import_bound("sys").unwrap().unbind(); + /// # let sys = py.import("sys").unwrap().unbind(); /// # version(sys, py).unwrap(); /// # }); /// ``` @@ -1906,7 +1906,7 @@ mod tests { #[test] fn test_call() { Python::with_gil(|py| { - let obj = py.get_type_bound::().to_object(py); + let obj = py.get_type::().to_object(py); let assert_repr = |obj: &Bound<'_, PyAny>, expected: &str| { assert_eq!(obj.repr().unwrap(), expected); diff --git a/src/lib.rs b/src/lib.rs index 82f1d271cf7..267639a271d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -235,10 +235,10 @@ //! //! fn main() -> PyResult<()> { //! Python::with_gil(|py| { -//! let sys = py.import_bound("sys")?; +//! let sys = py.import("sys")?; //! let version: String = sys.getattr("version")?.extract()?; //! -//! let locals = [("os", py.import_bound("os")?)].into_py_dict(py); +//! let locals = [("os", py.import("os")?)].into_py_dict(py); //! let code = "os.getenv('USER') or os.getenv('USERNAME') or 'Unknown'"; //! let user: String = py.eval_bound(code, None, Some(&locals))?.extract()?; //! diff --git a/src/macros.rs b/src/macros.rs index d2aff4bcbf1..d121efb367e 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -73,7 +73,7 @@ /// } /// /// Python::with_gil(|py| { -/// let locals = [("C", py.get_type_bound::())].into_py_dict(py); +/// let locals = [("C", py.get_type::())].into_py_dict(py); /// pyo3::py_run!(py, *locals, "c = C()"); /// }); /// ``` diff --git a/src/marker.rs b/src/marker.rs index e2d9a7938ec..778ccf61c7d 100644 --- a/src/marker.rs +++ b/src/marker.rs @@ -651,21 +651,43 @@ impl<'py> Python<'py> { /// Gets the Python type object for type `T`. #[inline] - pub fn get_type_bound(self) -> Bound<'py, PyType> + pub fn get_type(self) -> Bound<'py, PyType> where T: PyTypeInfo, { T::type_object_bound(self) } + /// Deprecated name for [`Python::get_type`]. + #[deprecated(since = "0.23.0", note = "renamed to `Python::get_type`")] + #[track_caller] + #[inline] + pub fn get_type_bound(self) -> Bound<'py, PyType> + where + T: PyTypeInfo, + { + self.get_type::() + } + /// Imports the Python module with the specified name. - pub fn import_bound(self, name: N) -> PyResult> + pub fn import(self, name: N) -> PyResult> where N: IntoPy>, { PyModule::import_bound(self, name) } + /// Deprecated name for [`Python::import`]. + #[deprecated(since = "0.23.0", note = "renamed to `Python::import`")] + #[track_caller] + #[inline] + pub fn import_bound(self, name: N) -> PyResult> + where + N: IntoPy>, + { + self.import(name) + } + /// Gets the Python builtin value `None`. #[allow(non_snake_case)] // the Python keyword starts with uppercase #[inline] diff --git a/src/pyclass_init.rs b/src/pyclass_init.rs index 2e73c1518d8..28b4a1cd719 100644 --- a/src/pyclass_init.rs +++ b/src/pyclass_init.rs @@ -121,7 +121,7 @@ impl PyObjectInit for PyNativeTypeInitializer { /// } /// } /// Python::with_gil(|py| { -/// let typeobj = py.get_type_bound::(); +/// let typeobj = py.get_type::(); /// let sub_sub_class = typeobj.call((), None).unwrap(); /// py_run!( /// py, diff --git a/src/sync.rs b/src/sync.rs index 441afa08cc2..60c8c4747a2 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -210,7 +210,7 @@ impl GILOnceCell> { ) -> PyResult<&Bound<'py, PyType>> { self.get_or_try_init(py, || { let type_object = py - .import_bound(module_name)? + .import(module_name)? .getattr(attr_name)? .downcast_into()?; Ok(type_object.unbind()) diff --git a/src/tests/common.rs b/src/tests/common.rs index c56249c2796..8180c4cd1af 100644 --- a/src/tests/common.rs +++ b/src/tests/common.rs @@ -42,7 +42,7 @@ mod inner { ($py:expr, *$dict:expr, $code:expr, $err:ident) => {{ let res = $py.run_bound($code, None, Some(&$dict.as_borrowed())); let err = res.expect_err(&format!("Did not raise {}", stringify!($err))); - if !err.matches($py, $py.get_type_bound::()) { + if !err.matches($py, $py.get_type::()) { panic!("Expected {} but got {:?}", stringify!($err), err) } err @@ -83,7 +83,7 @@ mod inner { #[cfg(all(feature = "macros", Py_3_8))] impl UnraisableCapture { pub fn install(py: Python<'_>) -> Py { - let sys = py.import_bound("sys").unwrap(); + let sys = py.import("sys").unwrap(); let old_hook = sys.getattr("unraisablehook").unwrap().into(); let capture = Py::new( @@ -104,7 +104,7 @@ mod inner { pub fn uninstall(&mut self, py: Python<'_>) { let old_hook = self.old_hook.take().unwrap(); - let sys = py.import_bound("sys").unwrap(); + let sys = py.import("sys").unwrap(); sys.setattr("unraisablehook", old_hook).unwrap(); } } @@ -118,7 +118,7 @@ mod inner { py: Python<'py>, f: impl FnOnce(&Bound<'py, PyList>) -> PyResult, ) -> PyResult { - let warnings = py.import_bound("warnings")?; + let warnings = py.import("warnings")?; let kwargs = [("record", true)].into_py_dict(py); let catch_warnings = warnings .getattr("catch_warnings")? diff --git a/src/types/any.rs b/src/types/any.rs index 72f141eec02..d3322d1c33f 100644 --- a/src/types/any.rs +++ b/src/types/any.rs @@ -75,7 +75,7 @@ pub trait PyAnyMethods<'py>: crate::sealed::Sealed { /// } /// # /// # Python::with_gil(|py| { - /// # let sys = py.import_bound("sys").unwrap(); + /// # let sys = py.import("sys").unwrap(); /// # has_version(&sys).unwrap(); /// # }); /// ``` @@ -101,7 +101,7 @@ pub trait PyAnyMethods<'py>: crate::sealed::Sealed { /// } /// # /// # Python::with_gil(|py| { - /// # let sys = py.import_bound("sys").unwrap(); + /// # let sys = py.import("sys").unwrap(); /// # version(&sys).unwrap(); /// # }); /// ``` @@ -1738,7 +1738,7 @@ class SimpleClass: fn test_any_is_instance() { Python::with_gil(|py| { let l = vec![1u8, 2].to_object(py).into_bound(py); - assert!(l.is_instance(&py.get_type_bound::()).unwrap()); + assert!(l.is_instance(&py.get_type::()).unwrap()); }); } @@ -1762,9 +1762,9 @@ class SimpleClass: fn test_any_is_exact_instance() { Python::with_gil(|py| { let t = PyBool::new(py, true); - assert!(t.is_instance(&py.get_type_bound::()).unwrap()); - assert!(!t.is_exact_instance(&py.get_type_bound::())); - assert!(t.is_exact_instance(&py.get_type_bound::())); + assert!(t.is_instance(&py.get_type::()).unwrap()); + assert!(!t.is_exact_instance(&py.get_type::())); + assert!(t.is_exact_instance(&py.get_type::())); }); } diff --git a/src/types/dict.rs b/src/types/dict.rs index 20664541f0c..0fb6a711013 100644 --- a/src/types/dict.rs +++ b/src/types/dict.rs @@ -748,7 +748,7 @@ mod tests { } Python::with_gil(|py| { - let class = py.get_type_bound::(); + let class = py.get_type::(); let instance = class.call0().unwrap(); let d = PyDict::new(py); match d.get_item(instance) { @@ -1188,7 +1188,7 @@ mod tests { let dict = abc_dict(py); let keys = dict.call_method0("keys").unwrap(); assert!(keys - .is_instance(&py.get_type_bound::().as_borrowed()) + .is_instance(&py.get_type::().as_borrowed()) .unwrap()); }) } @@ -1200,7 +1200,7 @@ mod tests { let dict = abc_dict(py); let values = dict.call_method0("values").unwrap(); assert!(values - .is_instance(&py.get_type_bound::().as_borrowed()) + .is_instance(&py.get_type::().as_borrowed()) .unwrap()); }) } @@ -1212,7 +1212,7 @@ mod tests { let dict = abc_dict(py); let items = dict.call_method0("items").unwrap(); assert!(items - .is_instance(&py.get_type_bound::().as_borrowed()) + .is_instance(&py.get_type::().as_borrowed()) .unwrap()); }) } diff --git a/src/types/string.rs b/src/types/string.rs index 2701e331ed7..e455389e47d 100644 --- a/src/types/string.rs +++ b/src/types/string.rs @@ -695,7 +695,7 @@ mod tests { let err = data.to_string(py).unwrap_err(); assert!(err .get_type_bound(py) - .is(&py.get_type_bound::())); + .is(&py.get_type::())); assert!(err .to_string() .contains("'utf-8' codec can't decode byte 0xfe in position 1")); @@ -739,7 +739,7 @@ mod tests { let err = data.to_string(py).unwrap_err(); assert!(err .get_type_bound(py) - .is(&py.get_type_bound::())); + .is(&py.get_type::())); assert!(err .to_string() .contains("'utf-16' codec can't decode bytes in position 0-3")); @@ -780,7 +780,7 @@ mod tests { let err = data.to_string(py).unwrap_err(); assert!(err .get_type_bound(py) - .is(&py.get_type_bound::())); + .is(&py.get_type::())); assert!(err .to_string() .contains("'utf-32' codec can't decode bytes in position 0-7")); diff --git a/src/types/traceback.rs b/src/types/traceback.rs index ef0062c6af9..98e40632439 100644 --- a/src/types/traceback.rs +++ b/src/types/traceback.rs @@ -63,7 +63,7 @@ impl<'py> PyTracebackMethods<'py> for Bound<'py, PyTraceback> { fn format(&self) -> PyResult { let py = self.py(); let string_io = py - .import_bound(intern!(py, "io"))? + .import(intern!(py, "io"))? .getattr(intern!(py, "StringIO"))? .call0()?; let result = unsafe { ffi::PyTraceBack_Print(self.as_ptr(), string_io.as_ptr()) }; diff --git a/src/types/typeobject.rs b/src/types/typeobject.rs index bbb1e5ef4cb..0c3b0a6aaa5 100644 --- a/src/types/typeobject.rs +++ b/src/types/typeobject.rs @@ -257,8 +257,8 @@ mod tests { #[test] fn test_type_is_subclass() { Python::with_gil(|py| { - let bool_type = py.get_type_bound::(); - let long_type = py.get_type_bound::(); + let bool_type = py.get_type::(); + let long_type = py.get_type::(); assert!(bool_type.is_subclass(&long_type).unwrap()); }); } @@ -266,10 +266,7 @@ mod tests { #[test] fn test_type_is_subclass_of() { Python::with_gil(|py| { - assert!(py - .get_type_bound::() - .is_subclass_of::() - .unwrap()); + assert!(py.get_type::().is_subclass_of::().unwrap()); }); } @@ -277,14 +274,14 @@ mod tests { fn test_mro() { Python::with_gil(|py| { assert!(py - .get_type_bound::() + .get_type::() .mro() .eq(PyTuple::new( py, [ - py.get_type_bound::(), - py.get_type_bound::(), - py.get_type_bound::() + py.get_type::(), + py.get_type::(), + py.get_type::() ] )) .unwrap()); @@ -295,9 +292,9 @@ mod tests { fn test_bases_bool() { Python::with_gil(|py| { assert!(py - .get_type_bound::() + .get_type::() .bases() - .eq(PyTuple::new(py, [py.get_type_bound::()])) + .eq(PyTuple::new(py, [py.get_type::()])) .unwrap()); }); } @@ -306,7 +303,7 @@ mod tests { fn test_bases_object() { Python::with_gil(|py| { assert!(py - .get_type_bound::() + .get_type::() .bases() .eq(PyTuple::empty(py)) .unwrap()); @@ -342,7 +339,7 @@ class MyClass: #[test] fn test_type_names_builtin() { Python::with_gil(|py| { - let bool_type = py.get_type_bound::(); + let bool_type = py.get_type::(); assert_eq!(bool_type.name().unwrap(), "bool"); assert_eq!(bool_type.qualname().unwrap(), "bool"); assert_eq!(bool_type.module().unwrap(), "builtins"); diff --git a/tests/test_class_attributes.rs b/tests/test_class_attributes.rs index 53ed16320d0..3f8eb74df5f 100644 --- a/tests/test_class_attributes.rs +++ b/tests/test_class_attributes.rs @@ -56,7 +56,7 @@ impl Foo { #[test] fn class_attributes() { Python::with_gil(|py| { - let foo_obj = py.get_type_bound::(); + let foo_obj = py.get_type::(); py_assert!(py, foo_obj, "foo_obj.MY_CONST == 'foobar'"); py_assert!(py, foo_obj, "foo_obj.RENAMED_CONST == 'foobar_2'"); py_assert!(py, foo_obj, "foo_obj.a == 5"); @@ -72,7 +72,7 @@ fn class_attributes() { #[ignore] fn class_attributes_are_immutable() { Python::with_gil(|py| { - let foo_obj = py.get_type_bound::(); + let foo_obj = py.get_type::(); py_expect_exception!(py, foo_obj, "foo_obj.a = 6", PyTypeError); }); } @@ -88,8 +88,8 @@ impl Bar { #[test] fn recursive_class_attributes() { Python::with_gil(|py| { - let foo_obj = py.get_type_bound::(); - let bar_obj = py.get_type_bound::(); + let foo_obj = py.get_type::(); + let bar_obj = py.get_type::(); py_assert!(py, foo_obj, "foo_obj.a_foo.x == 1"); py_assert!(py, foo_obj, "foo_obj.bar.x == 2"); py_assert!(py, bar_obj, "bar_obj.a_foo.x == 3"); @@ -107,9 +107,9 @@ fn test_fallible_class_attribute() { impl<'py> CaptureStdErr<'py> { fn new(py: Python<'py>) -> PyResult { - let sys = py.import_bound("sys")?; + let sys = py.import("sys")?; let oldstderr = sys.getattr("stderr")?; - let string_io = py.import_bound("io")?.getattr("StringIO")?.call0()?; + let string_io = py.import("io")?.getattr("StringIO")?.call0()?; sys.setattr("stderr", &string_io)?; Ok(Self { oldstderr, @@ -126,7 +126,7 @@ fn test_fallible_class_attribute() { .downcast::()? .to_cow()? .into_owned(); - let sys = py.import_bound("sys")?; + let sys = py.import("sys")?; sys.setattr("stderr", self.oldstderr)?; Ok(payload) } @@ -145,7 +145,7 @@ fn test_fallible_class_attribute() { Python::with_gil(|py| { let stderr = CaptureStdErr::new(py).unwrap(); - assert!(std::panic::catch_unwind(|| py.get_type_bound::()).is_err()); + assert!(std::panic::catch_unwind(|| py.get_type::()).is_err()); assert_eq!( stderr.reset().unwrap().trim(), "\ @@ -187,7 +187,7 @@ fn test_renaming_all_struct_fields() { use pyo3::types::PyBool; Python::with_gil(|py| { - let struct_class = py.get_type_bound::(); + let struct_class = py.get_type::(); let struct_obj = struct_class.call0().unwrap(); assert!(struct_obj .setattr("firstField", PyBool::new(py, false)) @@ -220,7 +220,7 @@ macro_rules! test_case { //use pyo3::types::PyInt; Python::with_gil(|py| { - let struct_class = py.get_type_bound::<$struct_name>(); + let struct_class = py.get_type::<$struct_name>(); let struct_obj = struct_class.call0().unwrap(); assert!(struct_obj.setattr($renamed_field_name, 2).is_ok()); let attr = struct_obj.getattr($renamed_field_name).unwrap(); diff --git a/tests/test_class_basics.rs b/tests/test_class_basics.rs index cb42e532154..947ab66f894 100644 --- a/tests/test_class_basics.rs +++ b/tests/test_class_basics.rs @@ -13,7 +13,7 @@ struct EmptyClass {} #[test] fn empty_class() { Python::with_gil(|py| { - let typeobj = py.get_type_bound::(); + let typeobj = py.get_type::(); // By default, don't allow creating instances from python. assert!(typeobj.call((), None).is_err()); @@ -27,7 +27,7 @@ struct UnitClass; #[test] fn unit_class() { Python::with_gil(|py| { - let typeobj = py.get_type_bound::(); + let typeobj = py.get_type::(); // By default, don't allow creating instances from python. assert!(typeobj.call((), None).is_err()); @@ -58,7 +58,7 @@ struct ClassWithDocs { #[test] fn class_with_docstr() { Python::with_gil(|py| { - let typeobj = py.get_type_bound::(); + let typeobj = py.get_type::(); py_run!( py, typeobj, @@ -104,7 +104,7 @@ impl EmptyClass2 { #[test] fn custom_names() { Python::with_gil(|py| { - let typeobj = py.get_type_bound::(); + let typeobj = py.get_type::(); py_assert!(py, typeobj, "typeobj.__name__ == 'CustomName'"); py_assert!(py, typeobj, "typeobj.custom_fn.__name__ == 'custom_fn'"); py_assert!( @@ -142,7 +142,7 @@ impl ClassRustKeywords { #[test] fn keyword_names() { Python::with_gil(|py| { - let typeobj = py.get_type_bound::(); + let typeobj = py.get_type::(); py_assert!(py, typeobj, "typeobj.__name__ == 'loop'"); py_assert!(py, typeobj, "typeobj.struct.__name__ == 'struct'"); py_assert!(py, typeobj, "typeobj.type.__name__ == 'type'"); @@ -167,7 +167,7 @@ impl RawIdents { #[test] fn test_raw_idents() { Python::with_gil(|py| { - let typeobj = py.get_type_bound::(); + let typeobj = py.get_type::(); py_assert!(py, typeobj, "not hasattr(typeobj, 'r#fn')"); py_assert!(py, typeobj, "hasattr(typeobj, 'fn')"); py_assert!(py, typeobj, "hasattr(typeobj, 'type')"); @@ -221,7 +221,7 @@ impl ClassWithObjectField { #[test] fn class_with_object_field() { Python::with_gil(|py| { - let ty = py.get_type_bound::(); + let ty = py.get_type::(); py_assert!(py, ty, "ty(5).value == 5"); py_assert!(py, ty, "ty(None).value == None"); }); @@ -405,7 +405,7 @@ struct TupleClass(#[pyo3(get, set, name = "value")] i32); #[test] fn test_tuple_struct_class() { Python::with_gil(|py| { - let typeobj = py.get_type_bound::(); + let typeobj = py.get_type::(); assert!(typeobj.call((), None).is_err()); py_assert!(py, typeobj, "typeobj.__name__ == 'TupleClass'"); diff --git a/tests/test_class_new.rs b/tests/test_class_new.rs index b5e5a2b8c9c..f2de5df42e2 100644 --- a/tests/test_class_new.rs +++ b/tests/test_class_new.rs @@ -19,7 +19,7 @@ impl EmptyClassWithNew { #[test] fn empty_class_with_new() { Python::with_gil(|py| { - let typeobj = py.get_type_bound::(); + let typeobj = py.get_type::(); assert!(typeobj .call((), None) .unwrap() @@ -48,7 +48,7 @@ impl UnitClassWithNew { #[test] fn unit_class_with_new() { Python::with_gil(|py| { - let typeobj = py.get_type_bound::(); + let typeobj = py.get_type::(); assert!(typeobj .call((), None) .unwrap() @@ -71,7 +71,7 @@ impl TupleClassWithNew { #[test] fn tuple_class_with_new() { Python::with_gil(|py| { - let typeobj = py.get_type_bound::(); + let typeobj = py.get_type::(); let wrp = typeobj.call((42,), None).unwrap(); let obj = wrp.downcast::().unwrap(); let obj_ref = obj.borrow(); @@ -96,7 +96,7 @@ impl NewWithOneArg { #[test] fn new_with_one_arg() { Python::with_gil(|py| { - let typeobj = py.get_type_bound::(); + let typeobj = py.get_type::(); let wrp = typeobj.call((42,), None).unwrap(); let obj = wrp.downcast::().unwrap(); let obj_ref = obj.borrow(); @@ -124,7 +124,7 @@ impl NewWithTwoArgs { #[test] fn new_with_two_args() { Python::with_gil(|py| { - let typeobj = py.get_type_bound::(); + let typeobj = py.get_type::(); let wrp = typeobj .call((10, 20), None) .map_err(|e| e.display(py)) @@ -155,7 +155,7 @@ impl SuperClass { #[test] fn subclass_new() { Python::with_gil(|py| { - let super_cls = py.get_type_bound::(); + let super_cls = py.get_type::(); let source = pyo3::indoc::indoc!( r#" class Class(SuperClass): @@ -200,7 +200,7 @@ impl NewWithCustomError { #[test] fn new_with_custom_error() { Python::with_gil(|py| { - let typeobj = py.get_type_bound::(); + let typeobj = py.get_type::(); let err = typeobj.call0().unwrap_err(); assert_eq!(err.to_string(), "ValueError: custom error"); }); @@ -235,7 +235,7 @@ impl NewExisting { #[test] fn test_new_existing() { Python::with_gil(|py| { - let typeobj = py.get_type_bound::(); + let typeobj = py.get_type::(); let obj1 = typeobj.call1((0,)).unwrap(); let obj2 = typeobj.call1((0,)).unwrap(); @@ -273,7 +273,7 @@ impl NewReturnsPy { #[test] fn test_new_returns_py() { Python::with_gil(|py| { - let type_ = py.get_type_bound::(); + let type_ = py.get_type::(); let obj = type_.call0().unwrap(); assert!(obj.is_exact_instance_of::()); }) @@ -293,7 +293,7 @@ impl NewReturnsBound { #[test] fn test_new_returns_bound() { Python::with_gil(|py| { - let type_ = py.get_type_bound::(); + let type_ = py.get_type::(); let obj = type_.call0().unwrap(); assert!(obj.is_exact_instance_of::()); }) @@ -319,7 +319,7 @@ impl NewClassMethod { #[test] fn test_new_class_method() { pyo3::Python::with_gil(|py| { - let cls = py.get_type_bound::(); + let cls = py.get_type::(); pyo3::py_run!(py, cls, "assert cls().cls is cls"); }); } diff --git a/tests/test_coroutine.rs b/tests/test_coroutine.rs index d99e7f80448..fc382489911 100644 --- a/tests/test_coroutine.rs +++ b/tests/test_coroutine.rs @@ -73,7 +73,7 @@ fn test_coroutine_qualname() { "my_fn", wrap_pyfunction!(my_fn, gil).unwrap().as_borrowed().as_any(), ), - ("MyClass", gil.get_type_bound::().as_any()), + ("MyClass", gil.get_type::().as_any()), ] .into_py_dict(gil); py_run!(gil, *locals, &handle_windows(test)); @@ -148,7 +148,7 @@ fn cancelled_coroutine() { await task asyncio.run(main()) "#; - let globals = gil.import_bound("__main__").unwrap().dict(); + let globals = gil.import("__main__").unwrap().dict(); globals.set_item("sleep", sleep).unwrap(); let err = gil .run_bound( @@ -187,7 +187,7 @@ fn coroutine_cancel_handle() { return await task assert asyncio.run(main()) == 0 "#; - let globals = gil.import_bound("__main__").unwrap().dict(); + let globals = gil.import("__main__").unwrap().dict(); globals .set_item("cancellable_sleep", cancellable_sleep) .unwrap(); @@ -219,7 +219,7 @@ fn coroutine_is_cancelled() { await task asyncio.run(main()) "#; - let globals = gil.import_bound("__main__").unwrap().dict(); + let globals = gil.import("__main__").unwrap().dict(); globals.set_item("sleep_loop", sleep_loop).unwrap(); gil.run_bound( &pyo3::unindent::unindent(&handle_windows(test)), @@ -316,7 +316,7 @@ fn test_async_method_receiver() { assert False assert asyncio.run(coro3) == 1 "#; - let locals = [("Counter", gil.get_type_bound::())].into_py_dict(gil); + let locals = [("Counter", gil.get_type::())].into_py_dict(gil); py_run!(gil, *locals, test); }); @@ -351,7 +351,7 @@ fn test_async_method_receiver_with_other_args() { assert asyncio.run(v.set_value(10)) == 10 assert asyncio.run(v.get_value_plus_with(1, 1)) == 12 "#; - let locals = [("Value", gil.get_type_bound::())].into_py_dict(gil); + let locals = [("Value", gil.get_type::())].into_py_dict(gil); py_run!(gil, *locals, test); }); } diff --git a/tests/test_datetime.rs b/tests/test_datetime.rs index da820e3d264..93492fc33a3 100644 --- a/tests/test_datetime.rs +++ b/tests/test_datetime.rs @@ -10,7 +10,7 @@ fn _get_subclasses<'py>( args: &str, ) -> PyResult<(Bound<'py, PyAny>, Bound<'py, PyAny>, Bound<'py, PyAny>)> { // Import the class from Python and create some subclasses - let datetime = py.import_bound("datetime")?; + let datetime = py.import("datetime")?; let locals = [(py_type, datetime.getattr(py_type)?)].into_py_dict(py); diff --git a/tests/test_datetime_import.rs b/tests/test_datetime_import.rs index 619df891944..68ef776a37a 100644 --- a/tests/test_datetime_import.rs +++ b/tests/test_datetime_import.rs @@ -14,7 +14,7 @@ fn test_bad_datetime_module_panic() { std::fs::File::create(tmpdir.join("datetime.py")).unwrap(); Python::with_gil(|py: Python<'_>| { - let sys = py.import_bound("sys").unwrap(); + let sys = py.import("sys").unwrap(); sys.getattr("path") .unwrap() .call_method1("insert", (0, tmpdir)) diff --git a/tests/test_enum.rs b/tests/test_enum.rs index cedb7ebaadb..abe743ee9ca 100644 --- a/tests/test_enum.rs +++ b/tests/test_enum.rs @@ -16,7 +16,7 @@ pub enum MyEnum { #[test] fn test_enum_class_attr() { Python::with_gil(|py| { - let my_enum = py.get_type_bound::(); + let my_enum = py.get_type::(); let var = Py::new(py, MyEnum::Variant).unwrap(); py_assert!(py, my_enum var, "my_enum.Variant == var"); }) @@ -31,7 +31,7 @@ fn return_enum() -> MyEnum { fn test_return_enum() { Python::with_gil(|py| { let f = wrap_pyfunction!(return_enum)(py).unwrap(); - let mynum = py.get_type_bound::(); + let mynum = py.get_type::(); py_run!(py, f mynum, "assert f() == mynum.Variant") }); @@ -46,7 +46,7 @@ fn enum_arg(e: MyEnum) { fn test_enum_arg() { Python::with_gil(|py| { let f = wrap_pyfunction!(enum_arg)(py).unwrap(); - let mynum = py.get_type_bound::(); + let mynum = py.get_type::(); py_run!(py, f mynum, "f(mynum.OtherVariant)") }) @@ -63,7 +63,7 @@ enum CustomDiscriminant { fn test_custom_discriminant() { Python::with_gil(|py| { #[allow(non_snake_case)] - let CustomDiscriminant = py.get_type_bound::(); + let CustomDiscriminant = py.get_type::(); let one = Py::new(py, CustomDiscriminant::One).unwrap(); let two = Py::new(py, CustomDiscriminant::Two).unwrap(); py_run!(py, CustomDiscriminant one two, r#" @@ -189,7 +189,7 @@ enum RenameAllVariantsEnum { #[test] fn test_renaming_all_enum_variants() { Python::with_gil(|py| { - let enum_obj = py.get_type_bound::(); + let enum_obj = py.get_type::(); py_assert!(py, enum_obj, "enum_obj.VARIANT_ONE == enum_obj.VARIANT_ONE"); py_assert!(py, enum_obj, "enum_obj.VARIANT_TWO == enum_obj.VARIANT_TWO"); py_assert!( @@ -209,7 +209,7 @@ enum CustomModuleComplexEnum { #[test] fn test_custom_module() { Python::with_gil(|py| { - let enum_obj = py.get_type_bound::(); + let enum_obj = py.get_type::(); py_assert!( py, enum_obj, @@ -340,7 +340,7 @@ mod deprecated { fn test_custom_discriminant() { Python::with_gil(|py| { #[allow(non_snake_case)] - let CustomDiscriminant = py.get_type_bound::(); + let CustomDiscriminant = py.get_type::(); let one = Py::new(py, CustomDiscriminant::One).unwrap(); let two = Py::new(py, CustomDiscriminant::Two).unwrap(); py_run!(py, CustomDiscriminant one two, r#" diff --git a/tests/test_gc.rs b/tests/test_gc.rs index b95abd4adea..0d54065c9c9 100644 --- a/tests/test_gc.rs +++ b/tests/test_gc.rs @@ -211,8 +211,8 @@ fn inheritance_with_new_methods_with_drop() { let drop_called2 = Arc::new(AtomicBool::new(false)); Python::with_gil(|py| { - let _typebase = py.get_type_bound::(); - let typeobj = py.get_type_bound::(); + let _typebase = py.get_type::(); + let typeobj = py.get_type::(); let inst = typeobj.call((), None).unwrap(); let obj = inst.downcast::().unwrap(); @@ -255,7 +255,7 @@ fn gc_during_borrow() { Python::with_gil(|py| { unsafe { // get the traverse function - let ty = py.get_type_bound::(); + let ty = py.get_type::(); let traverse = get_type_traverse(ty.as_type_ptr()).unwrap(); // create an object and check that traversing it works normally @@ -303,7 +303,7 @@ impl PartialTraverse { fn traverse_partial() { Python::with_gil(|py| unsafe { // get the traverse function - let ty = py.get_type_bound::(); + let ty = py.get_type::(); let traverse = get_type_traverse(ty.as_type_ptr()).unwrap(); // confirm that traversing errors @@ -338,7 +338,7 @@ impl PanickyTraverse { fn traverse_panic() { Python::with_gil(|py| unsafe { // get the traverse function - let ty = py.get_type_bound::(); + let ty = py.get_type::(); let traverse = get_type_traverse(ty.as_type_ptr()).unwrap(); // confirm that traversing errors @@ -361,7 +361,7 @@ impl TriesGILInTraverse { fn tries_gil_in_traverse() { Python::with_gil(|py| unsafe { // get the traverse function - let ty = py.get_type_bound::(); + let ty = py.get_type::(); let traverse = get_type_traverse(ty.as_type_ptr()).unwrap(); // confirm that traversing panicks @@ -414,7 +414,7 @@ impl<'a> Traversable for PyRef<'a, HijackedTraverse> { fn traverse_cannot_be_hijacked() { Python::with_gil(|py| unsafe { // get the traverse function - let ty = py.get_type_bound::(); + let ty = py.get_type::(); let traverse = get_type_traverse(ty.as_type_ptr()).unwrap(); let cell = Bound::new(py, HijackedTraverse::new()).unwrap(); @@ -536,7 +536,7 @@ fn unsendable_are_not_traversed_on_foreign_thread() { unsafe impl Send for SendablePtr {} Python::with_gil(|py| unsafe { - let ty = py.get_type_bound::(); + let ty = py.get_type::(); let traverse = get_type_traverse(ty.as_type_ptr()).unwrap(); let obj = Py::new( diff --git a/tests/test_getter_setter.rs b/tests/test_getter_setter.rs index a28030c4de0..dc67c040fc5 100644 --- a/tests/test_getter_setter.rs +++ b/tests/test_getter_setter.rs @@ -85,7 +85,7 @@ fn class_with_properties() { py_run!(py, inst, "inst.from_any = 15"); py_run!(py, inst, "assert inst.get_num() == 15"); - let d = [("C", py.get_type_bound::())].into_py_dict(py); + let d = [("C", py.get_type::())].into_py_dict(py); py_assert!(py, *d, "C.DATA.__doc__ == 'a getter for data'"); }); } diff --git a/tests/test_inheritance.rs b/tests/test_inheritance.rs index 6037ae1a57b..1f02edacbc8 100644 --- a/tests/test_inheritance.rs +++ b/tests/test_inheritance.rs @@ -20,7 +20,7 @@ struct SubclassAble {} #[test] fn subclass() { Python::with_gil(|py| { - let d = [("SubclassAble", py.get_type_bound::())].into_py_dict(py); + let d = [("SubclassAble", py.get_type::())].into_py_dict(py); py.run_bound( "class A(SubclassAble): pass\nassert issubclass(A, SubclassAble)", @@ -72,7 +72,7 @@ impl SubClass { #[test] fn inheritance_with_new_methods() { Python::with_gil(|py| { - let typeobj = py.get_type_bound::(); + let typeobj = py.get_type::(); let inst = typeobj.call((), None).unwrap(); py_run!(py, inst, "assert inst.val1 == 10; assert inst.val2 == 5"); }); @@ -112,8 +112,8 @@ fn mutation_fails() { #[test] fn is_subclass_and_is_instance() { Python::with_gil(|py| { - let sub_ty = py.get_type_bound::(); - let base_ty = py.get_type_bound::(); + let sub_ty = py.get_type::(); + let base_ty = py.get_type::(); assert!(sub_ty.is_subclass_of::().unwrap()); assert!(sub_ty.is_subclass(&base_ty).unwrap()); @@ -155,7 +155,7 @@ impl SubClass2 { #[test] fn handle_result_in_new() { Python::with_gil(|py| { - let subclass = py.get_type_bound::(); + let subclass = py.get_type::(); py_run!( py, subclass, @@ -274,7 +274,7 @@ mod inheriting_native_type { #[test] fn custom_exception() { Python::with_gil(|py| { - let cls = py.get_type_bound::(); + let cls = py.get_type::(); let dict = [("cls", &cls)].into_py_dict(py); let res = py.run_bound( "e = cls('hello'); assert str(e) == 'hello'; assert e.context == 'Hello :)'; raise e", @@ -315,7 +315,7 @@ fn test_subclass_ref_counts() { // regression test for issue #1363 Python::with_gil(|py| { #[allow(non_snake_case)] - let SimpleClass = py.get_type_bound::(); + let SimpleClass = py.get_type::(); py_run!( py, SimpleClass, diff --git a/tests/test_macro_docs.rs b/tests/test_macro_docs.rs index 2eb21c52a00..964e762886d 100644 --- a/tests/test_macro_docs.rs +++ b/tests/test_macro_docs.rs @@ -23,7 +23,7 @@ impl MacroDocs { #[test] fn meth_doc() { Python::with_gil(|py| { - let d = [("C", py.get_type_bound::())].into_py_dict(py); + let d = [("C", py.get_type::())].into_py_dict(py); py_assert!( py, *d, diff --git a/tests/test_macros.rs b/tests/test_macros.rs index 4bf2807f93a..40fd4847679 100644 --- a/tests/test_macros.rs +++ b/tests/test_macros.rs @@ -74,7 +74,7 @@ property_rename_via_macro!(my_new_property_name); #[test] fn test_macro_rules_interactions() { Python::with_gil(|py| { - let my_base = py.get_type_bound::(); + let my_base = py.get_type::(); py_assert!(py, my_base, "my_base.__name__ == 'MyClass'"); let my_func = wrap_pyfunction!(my_function_in_macro, py).unwrap(); @@ -84,7 +84,7 @@ fn test_macro_rules_interactions() { "my_func.__text_signature__ == '(a, b=None, *, c=42)'" ); - let renamed_prop = py.get_type_bound::(); + let renamed_prop = py.get_type::(); py_assert!( py, renamed_prop, diff --git a/tests/test_mapping.rs b/tests/test_mapping.rs index 65d07dd2611..1938c8837ff 100644 --- a/tests/test_mapping.rs +++ b/tests/test_mapping.rs @@ -71,7 +71,7 @@ impl Mapping { /// Return a dict with `m = Mapping(['1', '2', '3'])`. fn map_dict(py: Python<'_>) -> Bound<'_, pyo3::types::PyDict> { - let d = [("Mapping", py.get_type_bound::())].into_py_dict(py); + let d = [("Mapping", py.get_type::())].into_py_dict(py); py_run!(py, *d, "m = Mapping(['1', '2', '3'])"); d } diff --git a/tests/test_methods.rs b/tests/test_methods.rs index 159cc210133..ecf7f64e94c 100644 --- a/tests/test_methods.rs +++ b/tests/test_methods.rs @@ -86,7 +86,7 @@ impl ClassMethod { #[test] fn class_method() { Python::with_gil(|py| { - let d = [("C", py.get_type_bound::())].into_py_dict(py); + let d = [("C", py.get_type::())].into_py_dict(py); py_assert!(py, *d, "C.method() == 'ClassMethod.method()!'"); py_assert!(py, *d, "C().method() == 'ClassMethod.method()!'"); py_assert!( @@ -113,7 +113,7 @@ impl ClassMethodWithArgs { #[test] fn class_method_with_args() { Python::with_gil(|py| { - let d = [("C", py.get_type_bound::())].into_py_dict(py); + let d = [("C", py.get_type::())].into_py_dict(py); py_assert!( py, *d, @@ -144,7 +144,7 @@ fn static_method() { Python::with_gil(|py| { assert_eq!(StaticMethod::method(py), "StaticMethod.method()!"); - let d = [("C", py.get_type_bound::())].into_py_dict(py); + let d = [("C", py.get_type::())].into_py_dict(py); py_assert!(py, *d, "C.method() == 'StaticMethod.method()!'"); py_assert!(py, *d, "C().method() == 'StaticMethod.method()!'"); py_assert!(py, *d, "C.method.__doc__ == 'Test static method.'"); @@ -168,7 +168,7 @@ fn static_method_with_args() { Python::with_gil(|py| { assert_eq!(StaticMethodWithArgs::method(py, 1234), "0x4d2"); - let d = [("C", py.get_type_bound::())].into_py_dict(py); + let d = [("C", py.get_type::())].into_py_dict(py); py_assert!(py, *d, "C.method(1337) == '0x539'"); }); } @@ -677,7 +677,7 @@ impl MethDocs { #[test] fn meth_doc() { Python::with_gil(|py| { - let d = [("C", py.get_type_bound::())].into_py_dict(py); + let d = [("C", py.get_type::())].into_py_dict(py); py_assert!(py, *d, "C.__doc__ == 'A class with \"documentation\".'"); py_assert!( py, @@ -868,7 +868,7 @@ impl FromSequence { #[test] fn test_from_sequence() { Python::with_gil(|py| { - let typeobj = py.get_type_bound::(); + let typeobj = py.get_type::(); py_assert!(py, typeobj, "typeobj(range(0, 4)).numbers == [0, 1, 2, 3]"); }); } @@ -948,7 +948,7 @@ impl r#RawIdents { #[test] fn test_raw_idents() { Python::with_gil(|py| { - let raw_idents_type = py.get_type_bound::(); + let raw_idents_type = py.get_type::(); assert_eq!(raw_idents_type.qualname().unwrap(), "RawIdents"); py_run!( py, diff --git a/tests/test_multiple_pymethods.rs b/tests/test_multiple_pymethods.rs index 308220e78b2..13baeed3815 100644 --- a/tests/test_multiple_pymethods.rs +++ b/tests/test_multiple_pymethods.rs @@ -65,7 +65,7 @@ impl PyClassWithMultiplePyMethods { #[test] fn test_class_with_multiple_pymethods() { Python::with_gil(|py| { - let cls = py.get_type_bound::(); + let cls = py.get_type::(); py_assert!(py, cls, "cls()() == 'call'"); py_assert!(py, cls, "cls().method() == 'method'"); py_assert!(py, cls, "cls.classmethod() == 'classmethod'"); diff --git a/tests/test_proto_methods.rs b/tests/test_proto_methods.rs index 597eed9b7cf..6373640a2f9 100644 --- a/tests/test_proto_methods.rs +++ b/tests/test_proto_methods.rs @@ -668,7 +668,7 @@ impl OnceFuture { #[cfg(not(target_arch = "wasm32"))] // Won't work without wasm32 event loop (e.g., Pyodide has WebLoop) fn test_await() { Python::with_gil(|py| { - let once = py.get_type_bound::(); + let once = py.get_type::(); let source = r#" import asyncio import sys @@ -718,7 +718,7 @@ impl AsyncIterator { #[cfg(not(target_arch = "wasm32"))] // Won't work without wasm32 event loop (e.g., Pyodide has WebLoop) fn test_anext_aiter() { Python::with_gil(|py| { - let once = py.get_type_bound::(); + let once = py.get_type::(); let source = r#" import asyncio import sys @@ -740,7 +740,7 @@ asyncio.run(main()) let globals = PyModule::import_bound(py, "__main__").unwrap().dict(); globals.set_item("Once", once).unwrap(); globals - .set_item("AsyncIterator", py.get_type_bound::()) + .set_item("AsyncIterator", py.get_type::()) .unwrap(); py.run_bound(source, Some(&globals), None) .map_err(|e| e.display(py)) @@ -783,7 +783,7 @@ impl DescrCounter { #[test] fn descr_getset() { Python::with_gil(|py| { - let counter = py.get_type_bound::(); + let counter = py.get_type::(); let source = pyo3::indoc::indoc!( r#" class Class: diff --git a/tests/test_sequence.rs b/tests/test_sequence.rs index 22ae864c8cf..9ac8d6dbe89 100644 --- a/tests/test_sequence.rs +++ b/tests/test_sequence.rs @@ -107,7 +107,7 @@ impl ByteSequence { /// Return a dict with `s = ByteSequence([1, 2, 3])`. fn seq_dict(py: Python<'_>) -> Bound<'_, pyo3::types::PyDict> { - let d = [("ByteSequence", py.get_type_bound::())].into_py_dict(py); + let d = [("ByteSequence", py.get_type::())].into_py_dict(py); // Though we can construct `s` in Rust, let's test `__new__` works. py_run!(py, *d, "s = ByteSequence([1, 2, 3])"); d @@ -139,7 +139,7 @@ fn test_setitem() { #[test] fn test_delitem() { Python::with_gil(|py| { - let d = [("ByteSequence", py.get_type_bound::())].into_py_dict(py); + let d = [("ByteSequence", py.get_type::())].into_py_dict(py); py_run!( py, @@ -235,7 +235,7 @@ fn test_repeat() { #[test] fn test_inplace_repeat() { Python::with_gil(|py| { - let d = [("ByteSequence", py.get_type_bound::())].into_py_dict(py); + let d = [("ByteSequence", py.get_type::())].into_py_dict(py); py_run!( py, diff --git a/tests/test_static_slots.rs b/tests/test_static_slots.rs index 581459b7d6e..bd1cb0cdc8a 100644 --- a/tests/test_static_slots.rs +++ b/tests/test_static_slots.rs @@ -38,7 +38,7 @@ impl Count5 { /// Return a dict with `s = Count5()`. fn test_dict(py: Python<'_>) -> Bound<'_, pyo3::types::PyDict> { - let d = [("Count5", py.get_type_bound::())].into_py_dict(py); + let d = [("Count5", py.get_type::())].into_py_dict(py); // Though we can construct `s` in Rust, let's test `__new__` works. py_run!(py, *d, "s = Count5()"); d diff --git a/tests/test_super.rs b/tests/test_super.rs index b64fd57e687..4ff049824b0 100644 --- a/tests/test_super.rs +++ b/tests/test_super.rs @@ -43,7 +43,7 @@ impl SubClass { #[test] fn test_call_super_method() { Python::with_gil(|py| { - let cls = py.get_type_bound::(); + let cls = py.get_type::(); pyo3::py_run!( py, cls, diff --git a/tests/test_text_signature.rs b/tests/test_text_signature.rs index d9fcb83d3bd..7aceedd44c0 100644 --- a/tests/test_text_signature.rs +++ b/tests/test_text_signature.rs @@ -13,7 +13,7 @@ fn class_without_docs_or_signature() { struct MyClass {} Python::with_gil(|py| { - let typeobj = py.get_type_bound::(); + let typeobj = py.get_type::(); py_assert!(py, typeobj, "typeobj.__doc__ is None"); py_assert!(py, typeobj, "typeobj.__text_signature__ is None"); @@ -28,7 +28,7 @@ fn class_with_docs() { struct MyClass {} Python::with_gil(|py| { - let typeobj = py.get_type_bound::(); + let typeobj = py.get_type::(); py_assert!(py, typeobj, "typeobj.__doc__ == 'docs line1\\ndocs line2'"); py_assert!(py, typeobj, "typeobj.__text_signature__ is None"); @@ -52,7 +52,7 @@ fn class_with_signature_no_doc() { } Python::with_gil(|py| { - let typeobj = py.get_type_bound::(); + let typeobj = py.get_type::(); py_assert!(py, typeobj, "typeobj.__doc__ == ''"); py_assert!( py, @@ -81,7 +81,7 @@ fn class_with_docs_and_signature() { } Python::with_gil(|py| { - let typeobj = py.get_type_bound::(); + let typeobj = py.get_type::(); py_assert!(py, typeobj, "typeobj.__doc__ == 'docs line1\\ndocs line2'"); py_assert!( @@ -239,7 +239,7 @@ fn test_auto_test_signature_method() { } Python::with_gil(|py| { - let cls = py.get_type_bound::(); + let cls = py.get_type::(); #[cfg(any(not(Py_LIMITED_API), Py_3_10))] py_assert!(py, cls, "cls.__text_signature__ == '(a, b, c)'"); py_assert!( @@ -324,7 +324,7 @@ fn test_auto_test_signature_opt_out() { let f = wrap_pyfunction!(my_function_2)(py).unwrap(); py_assert!(py, f, "f.__text_signature__ == None"); - let cls = py.get_type_bound::(); + let cls = py.get_type::(); py_assert!(py, cls, "cls.__text_signature__ == None"); py_assert!(py, cls, "cls.method.__text_signature__ == None"); py_assert!(py, cls, "cls.method_2.__text_signature__ == None"); @@ -384,7 +384,7 @@ fn test_methods() { } Python::with_gil(|py| { - let typeobj = py.get_type_bound::(); + let typeobj = py.get_type::(); py_assert!( py, @@ -425,7 +425,7 @@ fn test_raw_identifiers() { } Python::with_gil(|py| { - let typeobj = py.get_type_bound::(); + let typeobj = py.get_type::(); py_assert!(py, typeobj, "typeobj.__text_signature__ == '()'"); diff --git a/tests/test_variable_arguments.rs b/tests/test_variable_arguments.rs index 3724689d836..d8d9c79e31a 100644 --- a/tests/test_variable_arguments.rs +++ b/tests/test_variable_arguments.rs @@ -27,7 +27,7 @@ impl MyClass { #[test] fn variable_args() { Python::with_gil(|py| { - let my_obj = py.get_type_bound::(); + let my_obj = py.get_type::(); py_assert!(py, my_obj, "my_obj.test_args() == ()"); py_assert!(py, my_obj, "my_obj.test_args(1) == (1,)"); py_assert!(py, my_obj, "my_obj.test_args(1, 2) == (1, 2)"); @@ -37,7 +37,7 @@ fn variable_args() { #[test] fn variable_kwargs() { Python::with_gil(|py| { - let my_obj = py.get_type_bound::(); + let my_obj = py.get_type::(); py_assert!(py, my_obj, "my_obj.test_kwargs() == None"); py_assert!(py, my_obj, "my_obj.test_kwargs(test=1) == {'test': 1}"); py_assert!( diff --git a/tests/ui/invalid_intern_arg.rs b/tests/ui/invalid_intern_arg.rs index eb479431b90..ac82fed97d8 100644 --- a/tests/ui/invalid_intern_arg.rs +++ b/tests/ui/invalid_intern_arg.rs @@ -2,5 +2,5 @@ use pyo3::Python; fn main() { let _foo = if true { "foo" } else { "bar" }; - Python::with_gil(|py| py.import_bound(pyo3::intern!(py, _foo)).unwrap()); + Python::with_gil(|py| py.import(pyo3::intern!(py, _foo)).unwrap()); } diff --git a/tests/ui/invalid_intern_arg.stderr b/tests/ui/invalid_intern_arg.stderr index 7d1aad1ae28..7b02b72a214 100644 --- a/tests/ui/invalid_intern_arg.stderr +++ b/tests/ui/invalid_intern_arg.stderr @@ -1,17 +1,17 @@ error[E0435]: attempt to use a non-constant value in a constant - --> tests/ui/invalid_intern_arg.rs:5:61 + --> tests/ui/invalid_intern_arg.rs:5:55 | -5 | Python::with_gil(|py| py.import_bound(pyo3::intern!(py, _foo)).unwrap()); - | ------------------^^^^- - | | | - | | non-constant value - | help: consider using `let` instead of `static`: `let INTERNED` +5 | Python::with_gil(|py| py.import(pyo3::intern!(py, _foo)).unwrap()); + | ------------------^^^^- + | | | + | | non-constant value + | help: consider using `let` instead of `static`: `let INTERNED` error: lifetime may not live long enough --> tests/ui/invalid_intern_arg.rs:5:27 | -5 | Python::with_gil(|py| py.import_bound(pyo3::intern!(py, _foo)).unwrap()); - | --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'2` +5 | Python::with_gil(|py| py.import(pyo3::intern!(py, _foo)).unwrap()); + | --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'2` | | | | | return type of closure is pyo3::Bound<'2, PyModule> | has type `Python<'1>`