From 4ce9c35983712b76645864ade4ced46f9a5748f7 Mon Sep 17 00:00:00 2001 From: Icxolu <10486322+Icxolu@users.noreply.github.com> Date: Sun, 18 Feb 2024 19:27:19 +0100 Subject: [PATCH] port `Python::get_type` to `Bound` API (#3846) * port `Python::get_type` to `Bound` API * fix `is_subclass_and_is_instance` FIXME --- guide/src/class.md | 22 +++++++++--------- guide/src/exception.md | 4 ++-- pyo3-macros-backend/src/pyclass.rs | 2 +- src/conversions/chrono.rs | 6 ++--- src/conversions/num_bigint.rs | 8 ++----- src/err/mod.rs | 10 ++++---- src/exceptions.rs | 17 +++++++------- src/impl_/extract_argument.rs | 5 +++- src/macros.rs | 2 +- src/marker.rs | 18 ++++++++++++++- src/pyclass_init.rs | 2 +- src/tests/common.rs | 2 +- src/types/typeobject.rs | 12 ++++++---- tests/test_class_attributes.rs | 16 ++++++------- tests/test_class_basics.rs | 14 +++++------ tests/test_class_new.rs | 37 ++++++++++++++---------------- tests/test_coroutine.rs | 11 +++++---- tests/test_enum.rs | 10 ++++---- tests/test_gc.rs | 30 ++++++++++++------------ tests/test_getter_setter.rs | 2 +- tests/test_inheritance.rs | 26 ++++++++++----------- 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_no_imports.rs | 14 ++++++----- 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 ++-- 33 files changed, 175 insertions(+), 157 deletions(-) diff --git a/guide/src/class.md b/guide/src/class.md index 6ca582ed..9a2d91c1 100644 --- a/guide/src/class.md +++ b/guide/src/class.md @@ -401,7 +401,7 @@ impl SubSubClass { # pyo3::py_run!(py, subsub, "assert subsub.method3() == 3000"); # let subsub = SubSubClass::factory_method(py, 2).unwrap(); # let subsubsub = SubSubClass::factory_method(py, 3).unwrap(); -# let cls = py.get_type::(); +# let cls = py.get_type_bound::(); # pyo3::py_run!(py, subsub cls, "assert not isinstance(subsub, cls)"); # pyo3::py_run!(py, subsubsub cls, "assert isinstance(subsubsub, cls)"); # }); @@ -497,7 +497,7 @@ impl MyDict { // some custom methods that use `private` here... } # Python::with_gil(|py| { -# let cls = py.get_type::(); +# let cls = py.get_type_bound::(); # pyo3::py_run!(py, cls, "cls(a=1, b=2)") # }); # } @@ -767,7 +767,7 @@ impl MyClass { } Python::with_gil(|py| { - let my_class = py.get_type::(); + let my_class = py.get_type_bound::(); pyo3::py_run!(py, my_class, "assert my_class.my_attribute == 'hello'") }); ``` @@ -1026,7 +1026,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::(); + let cls = py.get_type_bound::(); pyo3::py_run!(py, x y cls, r#" assert x == cls.Variant assert y == cls.OtherVariant @@ -1046,7 +1046,7 @@ enum MyEnum { } Python::with_gil(|py| { - let cls = py.get_type::(); + let cls = py.get_type_bound::(); 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 @@ -1068,7 +1068,7 @@ enum MyEnum{ } Python::with_gil(|py| { - let cls = py.get_type::(); + let cls = py.get_type_bound::(); let x = Py::new(py, MyEnum::Variant).unwrap(); pyo3::py_run!(py, cls x, r#" assert repr(x) == 'MyEnum.Variant' @@ -1094,7 +1094,7 @@ impl MyEnum { } Python::with_gil(|py| { - let cls = py.get_type::(); + let cls = py.get_type_bound::(); pyo3::py_run!(py, cls, "assert repr(cls.Answer) == '42'") }) ``` @@ -1111,7 +1111,7 @@ enum MyEnum { Python::with_gil(|py| { let x = Py::new(py, MyEnum::Variant).unwrap(); - let cls = py.get_type::(); + let cls = py.get_type_bound::(); pyo3::py_run!(py, x cls, r#" assert repr(x) == 'RenamedEnum.UPPERCASE' assert x == cls.UPPERCASE @@ -1165,7 +1165,7 @@ enum Shape { Python::with_gil(|py| { let circle = Shape::Circle { radius: 10.0 }.into_py(py); let square = Shape::RegularPolygon { side_count: 4, radius: 10.0 }.into_py(py); - let cls = py.get_type::(); + let cls = py.get_type_bound::(); pyo3::py_run!(py, circle square cls, r#" assert isinstance(circle, cls) assert isinstance(circle, cls.Circle) @@ -1204,7 +1204,7 @@ enum MyEnum { Python::with_gil(|py| { let x = Py::new(py, MyEnum::Variant { i: 42 }).unwrap(); - let cls = py.get_type::(); + let cls = py.get_type_bound::(); pyo3::py_run!(py, x cls, r#" assert isinstance(x, cls) assert not isinstance(x, cls.Variant) @@ -1308,7 +1308,7 @@ impl pyo3::impl_::pyclass::PyClassImpl for MyClass { } # Python::with_gil(|py| { -# let cls = py.get_type::(); +# let cls = py.get_type_bound::(); # pyo3::py_run!(py, cls, "assert cls.__name__ == 'MyClass'") # }); # } diff --git a/guide/src/exception.md b/guide/src/exception.md index 22511857..0be44167 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::())].into_py_dict_bound(py); + let ctx = [("CustomError", py.get_type_bound::())].into_py_dict_bound(py); pyo3::py_run!( py, *ctx, @@ -46,7 +46,7 @@ pyo3::create_exception!(mymodule, CustomError, PyException); #[pymodule] fn mymodule(py: Python<'_>, m: &PyModule) -> PyResult<()> { // ... other elements added to module ... - m.add("CustomError", py.get_type::())?; + m.add("CustomError", py.get_type_bound::())?; Ok(()) } diff --git a/pyo3-macros-backend/src/pyclass.rs b/pyo3-macros-backend/src/pyclass.rs index 02024011..7d8c868e 100644 --- a/pyo3-macros-backend/src/pyclass.rs +++ b/pyo3-macros-backend/src/pyclass.rs @@ -1086,7 +1086,7 @@ pub fn gen_complex_enum_variant_attr( let associated_method = quote! { fn #wrapper_ident(py: _pyo3::Python<'_>) -> _pyo3::PyResult<_pyo3::PyObject> { #deprecations - ::std::result::Result::Ok(py.get_type::<#variant_cls>().into()) + ::std::result::Result::Ok(py.get_type_bound::<#variant_cls>().into_any().unbind()) } }; diff --git a/src/conversions/chrono.rs b/src/conversions/chrono.rs index 6737c16f..6878b9d9 100644 --- a/src/conversions/chrono.rs +++ b/src/conversions/chrono.rs @@ -52,9 +52,7 @@ use crate::types::{ }; #[cfg(Py_LIMITED_API)] use crate::{intern, DowncastError}; -use crate::{ - Bound, FromPyObject, IntoPy, PyAny, PyErr, PyNativeType, PyObject, PyResult, Python, ToPyObject, -}; +use crate::{Bound, FromPyObject, IntoPy, PyAny, PyErr, PyObject, PyResult, Python, ToPyObject}; use chrono::offset::{FixedOffset, Utc}; use chrono::{ DateTime, Datelike, Duration, NaiveDate, NaiveDateTime, NaiveTime, Offset, TimeZone, Timelike, @@ -461,7 +459,7 @@ fn warn_truncated_leap_second(obj: &Bound<'_, PyAny>) { let py = obj.py(); if let Err(e) = PyErr::warn_bound( py, - &py.get_type::().as_borrowed(), + &py.get_type_bound::(), "ignored leap-second, `datetime` does not support leap-seconds", 0, ) { diff --git a/src/conversions/num_bigint.rs b/src/conversions/num_bigint.rs index ff5bd030..3c98a90f 100644 --- a/src/conversions/num_bigint.rs +++ b/src/conversions/num_bigint.rs @@ -91,12 +91,8 @@ macro_rules! bigint_conversion { } else { None }; - py.get_type::() - .call_method( - "from_bytes", - (bytes_obj, "little"), - kwargs.as_ref().map(crate::Bound::as_gil_ref), - ) + py.get_type_bound::() + .call_method("from_bytes", (bytes_obj, "little"), kwargs.as_ref()) .expect("int.from_bytes() failed during to_object()") // FIXME: #1813 or similar .into() } diff --git a/src/err/mod.rs b/src/err/mod.rs index d55c8f45..d922baaa 100644 --- a/src/err/mod.rs +++ b/src/err/mod.rs @@ -724,7 +724,7 @@ impl PyErr { /// # use pyo3::prelude::*; /// # fn main() -> PyResult<()> { /// Python::with_gil(|py| { - /// let user_warning = py.get_type::().as_borrowed(); + /// let user_warning = py.get_type_bound::(); /// PyErr::warn_bound(py, &user_warning, "I am warning you", 0)?; /// Ok(()) /// }) @@ -1080,7 +1080,7 @@ impl_signed_integer!(isize); mod tests { use super::PyErrState; use crate::exceptions::{self, PyTypeError, PyValueError}; - use crate::{PyErr, PyNativeType, PyTypeInfo, Python}; + use crate::{PyErr, PyTypeInfo, Python}; #[test] fn no_error() { @@ -1278,7 +1278,7 @@ mod tests { // GIL locked should prevent effects to be visible to other testing // threads. Python::with_gil(|py| { - let cls = py.get_type::().as_borrowed(); + let cls = py.get_type_bound::(); // Reset warning filter to default state let warnings = py.import_bound("warnings").unwrap(); @@ -1293,14 +1293,14 @@ mod tests { // Test with raising warnings - .call_method1("simplefilter", ("error", cls)) + .call_method1("simplefilter", ("error", &cls)) .unwrap(); PyErr::warn_bound(py, &cls, "I am warning you", 0).unwrap_err(); // Test with error for an explicit module warnings.call_method0("resetwarnings").unwrap(); warnings - .call_method1("filterwarnings", ("error", "", cls, "pyo3test")) + .call_method1("filterwarnings", ("error", "", &cls, "pyo3test")) .unwrap(); // This has the wrong module and will not raise, just be emitted diff --git a/src/exceptions.rs b/src/exceptions.rs index e7b6407e..6ae9febc 100644 --- a/src/exceptions.rs +++ b/src/exceptions.rs @@ -72,7 +72,7 @@ macro_rules! impl_exception_boilerplate { /// import_exception!(socket, gaierror); /// /// Python::with_gil(|py| { -/// let ctx = [("gaierror", py.get_type::())].into_py_dict_bound(py); +/// let ctx = [("gaierror", py.get_type_bound::())].into_py_dict_bound(py); /// pyo3::py_run!(py, *ctx, "import socket; assert gaierror is socket.gaierror"); /// }); /// @@ -160,7 +160,7 @@ macro_rules! import_exception { /// /// #[pymodule] /// fn my_module(py: Python<'_>, m: &PyModule) -> PyResult<()> { -/// m.add("MyError", py.get_type::())?; +/// m.add("MyError", py.get_type_bound::())?; /// m.add_function(wrap_pyfunction!(raise_myerror, py)?)?; /// Ok(()) /// } @@ -168,7 +168,7 @@ macro_rules! import_exception { /// # Python::with_gil(|py| -> PyResult<()> { /// # let fun = wrap_pyfunction!(raise_myerror, py)?; /// # let locals = pyo3::types::PyDict::new_bound(py); -/// # locals.set_item("MyError", py.get_type::())?; +/// # locals.set_item("MyError", py.get_type_bound::())?; /// # locals.set_item("raise_myerror", fun)?; /// # /// # py.run_bound( @@ -241,7 +241,6 @@ macro_rules! create_exception_type_object { impl $name { fn type_object_raw(py: $crate::Python<'_>) -> *mut $crate::ffi::PyTypeObject { use $crate::sync::GILOnceCell; - use $crate::PyNativeType; static TYPE_OBJECT: GILOnceCell<$crate::Py<$crate::types::PyType>> = GILOnceCell::new(); @@ -251,7 +250,7 @@ macro_rules! create_exception_type_object { py, concat!(stringify!($module), ".", stringify!($name)), $doc, - ::std::option::Option::Some(&py.get_type::<$base>().as_borrowed()), + ::std::option::Option::Some(&py.get_type_bound::<$base>()), ::std::option::Option::None, ).expect("Failed to initialize new exception type.") ).as_ptr() as *mut $crate::ffi::PyTypeObject @@ -904,7 +903,7 @@ mod tests { create_exception!(mymodule, CustomError, PyException); Python::with_gil(|py| { - let error_type = py.get_type::(); + let error_type = py.get_type_bound::(); let ctx = [("CustomError", error_type)].into_py_dict_bound(py); let type_description: String = py .eval_bound("str(CustomError)", None, Some(&ctx)) @@ -927,7 +926,7 @@ mod tests { fn custom_exception_dotted_module() { create_exception!(mymodule.exceptions, CustomError, PyException); Python::with_gil(|py| { - let error_type = py.get_type::(); + let error_type = py.get_type_bound::(); let ctx = [("CustomError", error_type)].into_py_dict_bound(py); let type_description: String = py .eval_bound("str(CustomError)", None, Some(&ctx)) @@ -946,7 +945,7 @@ mod tests { create_exception!(mymodule, CustomError, PyException, "Some docs"); Python::with_gil(|py| { - let error_type = py.get_type::(); + let error_type = py.get_type_bound::(); let ctx = [("CustomError", error_type)].into_py_dict_bound(py); let type_description: String = py .eval_bound("str(CustomError)", None, Some(&ctx)) @@ -979,7 +978,7 @@ mod tests { ); Python::with_gil(|py| { - let error_type = py.get_type::(); + let error_type = py.get_type_bound::(); let ctx = [("CustomError", error_type)].into_py_dict_bound(py); let type_description: String = py .eval_bound("str(CustomError)", None, Some(&ctx)) diff --git a/src/impl_/extract_argument.rs b/src/impl_/extract_argument.rs index d9487359..27728c6d 100644 --- a/src/impl_/extract_argument.rs +++ b/src/impl_/extract_argument.rs @@ -166,7 +166,10 @@ pub fn from_py_with_with_default<'a, 'py, T>( #[cold] pub fn argument_extraction_error(py: Python<'_>, arg_name: &str, error: PyErr) -> PyErr { use crate::types::any::PyAnyMethods; - if error.get_type_bound(py).is(py.get_type::()) { + if error + .get_type_bound(py) + .is(&py.get_type_bound::()) + { let remapped_error = PyTypeError::new_err(format!( "argument '{}': {}", arg_name, diff --git a/src/macros.rs b/src/macros.rs index d5fbbdc3..0779fb98 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -73,7 +73,7 @@ /// } /// /// Python::with_gil(|py| { -/// let locals = [("C", py.get_type::())].into_py_dict_bound(py); +/// let locals = [("C", py.get_type_bound::())].into_py_dict_bound(py); /// pyo3::py_run!(py, *locals, "c = C()"); /// }); /// ``` diff --git a/src/marker.rs b/src/marker.rs index 5321eddb..4b46d3ba 100644 --- a/src/marker.rs +++ b/src/marker.rs @@ -728,12 +728,28 @@ impl<'py> Python<'py> { } /// Gets the Python type object for type `T`. + #[cfg_attr( + not(feature = "gil-refs"), + deprecated( + since = "0.21.0", + note = "`Python::get_type` will be replaced by `Python::get_type_bound` in a future PyO3 version" + ) + )] #[inline] pub fn get_type(self) -> &'py PyType where T: PyTypeInfo, { - T::type_object_bound(self).into_gil_ref() + self.get_type_bound::().into_gil_ref() + } + + /// Gets the Python type object for type `T`. + #[inline] + pub fn get_type_bound(self) -> Bound<'py, PyType> + where + T: PyTypeInfo, + { + T::type_object_bound(self) } /// Deprecated form of [`Python::import_bound`] diff --git a/src/pyclass_init.rs b/src/pyclass_init.rs index 63761f43..ac3aa3ef 100644 --- a/src/pyclass_init.rs +++ b/src/pyclass_init.rs @@ -122,7 +122,7 @@ impl PyObjectInit for PyNativeTypeInitializer { /// } /// } /// Python::with_gil(|py| { -/// let typeobj = py.get_type::(); +/// let typeobj = py.get_type_bound::(); /// let sub_sub_class = typeobj.call((), None).unwrap(); /// py_run!( /// py, diff --git a/src/tests/common.rs b/src/tests/common.rs index 5eec6094..854d73e4 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::()) { + if !err.matches($py, $py.get_type_bound::()) { panic!("Expected {} but got {:?}", stringify!($err), err) } err diff --git a/src/types/typeobject.rs b/src/types/typeobject.rs index f0e4a8c0..4c1b17a2 100644 --- a/src/types/typeobject.rs +++ b/src/types/typeobject.rs @@ -217,22 +217,26 @@ impl<'a> Borrowed<'a, '_, PyType> { #[cfg(test)] mod tests { + use crate::types::typeobject::PyTypeMethods; use crate::types::{PyBool, PyLong}; use crate::Python; #[test] fn test_type_is_subclass() { Python::with_gil(|py| { - let bool_type = py.get_type::(); - let long_type = py.get_type::(); - assert!(bool_type.is_subclass(long_type).unwrap()); + let bool_type = py.get_type_bound::(); + let long_type = py.get_type_bound::(); + assert!(bool_type.is_subclass(&long_type).unwrap()); }); } #[test] fn test_type_is_subclass_of() { Python::with_gil(|py| { - assert!(py.get_type::().is_subclass_of::().unwrap()); + assert!(py + .get_type_bound::() + .is_subclass_of::() + .unwrap()); }); } } diff --git a/tests/test_class_attributes.rs b/tests/test_class_attributes.rs index 906a11c8..9e544211 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::(); + let foo_obj = py.get_type_bound::(); 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::(); + let foo_obj = py.get_type_bound::(); 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::(); - let bar_obj = py.get_type::(); + let foo_obj = py.get_type_bound::(); + let bar_obj = py.get_type_bound::(); 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"); @@ -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::()).is_err()); + assert!(std::panic::catch_unwind(|| py.get_type_bound::()).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::(); + let struct_class = py.get_type_bound::(); let struct_obj = struct_class.call0().unwrap(); assert!(struct_obj .setattr("firstField", PyBool::new_bound(py, false)) @@ -220,11 +220,11 @@ macro_rules! test_case { //use pyo3::types::PyInt; Python::with_gil(|py| { - let struct_class = py.get_type::<$struct_name>(); + let struct_class = py.get_type_bound::<$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(); - assert_eq!(2, PyAny::extract::(attr).unwrap()); + assert_eq!(2, attr.extract().unwrap()); }); } }; diff --git a/tests/test_class_basics.rs b/tests/test_class_basics.rs index 1c2b2a5c..6d282765 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::(); + let typeobj = py.get_type_bound::(); // 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::(); + let typeobj = py.get_type_bound::(); // 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::(); + let typeobj = py.get_type_bound::(); py_run!( py, typeobj, @@ -104,7 +104,7 @@ impl EmptyClass2 { #[test] fn custom_names() { Python::with_gil(|py| { - let typeobj = py.get_type::(); + let typeobj = py.get_type_bound::(); py_assert!(py, typeobj, "typeobj.__name__ == 'CustomName'"); py_assert!(py, typeobj, "typeobj.custom_fn.__name__ == 'custom_fn'"); py_assert!( @@ -137,7 +137,7 @@ impl RawIdents { #[test] fn test_raw_idents() { Python::with_gil(|py| { - let typeobj = py.get_type::(); + let typeobj = py.get_type_bound::(); py_assert!(py, typeobj, "not hasattr(typeobj, 'r#fn')"); py_assert!(py, typeobj, "hasattr(typeobj, 'fn')"); py_assert!(py, typeobj, "hasattr(typeobj, 'type')"); @@ -191,7 +191,7 @@ impl ClassWithObjectField { #[test] fn class_with_object_field() { Python::with_gil(|py| { - let ty = py.get_type::(); + let ty = py.get_type_bound::(); py_assert!(py, ty, "ty(5).value == 5"); py_assert!(py, ty, "ty(None).value == None"); }); @@ -346,7 +346,7 @@ struct TupleClass(#[pyo3(get, set, name = "value")] i32); #[test] fn test_tuple_struct_class() { Python::with_gil(|py| { - let typeobj = py.get_type::(); + let typeobj = py.get_type_bound::(); 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 59772cc4..b1a0e594 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::(); + let typeobj = py.get_type_bound::(); assert!(typeobj .call((), None) .unwrap() @@ -29,10 +29,7 @@ fn empty_class_with_new() { // Calling with arbitrary args or kwargs is not ok assert!(typeobj.call(("some", "args"), None).is_err()); assert!(typeobj - .call( - (), - Some([("some", "kwarg")].into_py_dict_bound(py).as_gil_ref()) - ) + .call((), Some(&[("some", "kwarg")].into_py_dict_bound(py))) .is_err()); }); } @@ -51,7 +48,7 @@ impl UnitClassWithNew { #[test] fn unit_class_with_new() { Python::with_gil(|py| { - let typeobj = py.get_type::(); + let typeobj = py.get_type_bound::(); assert!(typeobj .call((), None) .unwrap() @@ -74,9 +71,9 @@ impl TupleClassWithNew { #[test] fn tuple_class_with_new() { Python::with_gil(|py| { - let typeobj = py.get_type::(); + let typeobj = py.get_type_bound::(); let wrp = typeobj.call((42,), None).unwrap(); - let obj = wrp.downcast::>().unwrap(); + let obj = wrp.downcast::().unwrap(); let obj_ref = obj.borrow(); assert_eq!(obj_ref.0, 42); }); @@ -99,9 +96,9 @@ impl NewWithOneArg { #[test] fn new_with_one_arg() { Python::with_gil(|py| { - let typeobj = py.get_type::(); + let typeobj = py.get_type_bound::(); let wrp = typeobj.call((42,), None).unwrap(); - let obj = wrp.downcast::>().unwrap(); + let obj = wrp.downcast::().unwrap(); let obj_ref = obj.borrow(); assert_eq!(obj_ref.data, 42); }); @@ -127,12 +124,12 @@ impl NewWithTwoArgs { #[test] fn new_with_two_args() { Python::with_gil(|py| { - let typeobj = py.get_type::(); + let typeobj = py.get_type_bound::(); let wrp = typeobj .call((10, 20), None) .map_err(|e| e.display(py)) .unwrap(); - let obj = wrp.downcast::>().unwrap(); + let obj = wrp.downcast::().unwrap(); let obj_ref = obj.borrow(); assert_eq!(obj_ref.data1, 10); assert_eq!(obj_ref.data2, 20); @@ -158,7 +155,7 @@ impl SuperClass { #[test] fn subclass_new() { Python::with_gil(|py| { - let super_cls = py.get_type::(); + let super_cls = py.get_type_bound::(); let source = pyo3::indoc::indoc!( r#" class Class(SuperClass): @@ -206,7 +203,7 @@ impl NewWithCustomError { #[test] fn new_with_custom_error() { Python::with_gil(|py| { - let typeobj = py.get_type::(); + let typeobj = py.get_type_bound::(); let err = typeobj.call0().unwrap_err(); assert_eq!(err.to_string(), "ValueError: custom error"); }); @@ -247,7 +244,7 @@ impl NewExisting { #[test] fn test_new_existing() { Python::with_gil(|py| { - let typeobj = py.get_type::(); + let typeobj = py.get_type_bound::(); let obj1 = typeobj.call1((0,)).unwrap(); let obj2 = typeobj.call1((0,)).unwrap(); @@ -263,10 +260,10 @@ fn test_new_existing() { assert!(obj5.getattr("num").unwrap().extract::().unwrap() == 2); assert!(obj6.getattr("num").unwrap().extract::().unwrap() == 2); - assert!(obj1.is(obj2)); - assert!(obj3.is(obj4)); - assert!(!obj1.is(obj3)); - assert!(!obj1.is(obj5)); - assert!(!obj5.is(obj6)); + assert!(obj1.is(&obj2)); + assert!(obj3.is(&obj4)); + assert!(!obj1.is(&obj3)); + assert!(!obj1.is(&obj5)); + assert!(!obj5.is(&obj6)); }); } diff --git a/tests/test_coroutine.rs b/tests/test_coroutine.rs index 5954b979..b3b8ba7b 100644 --- a/tests/test_coroutine.rs +++ b/tests/test_coroutine.rs @@ -1,6 +1,6 @@ #![cfg(feature = "macros")] #![cfg(not(target_arch = "wasm32"))] -use std::{ops::Deref, task::Poll, thread, time::Duration}; +use std::{task::Poll, thread, time::Duration}; use futures::{channel::oneshot, future::poll_fn, FutureExt}; use pyo3::{ @@ -65,8 +65,11 @@ fn test_coroutine_qualname() { assert coro.__name__ == name and coro.__qualname__ == qualname "#; let locals = [ - ("my_fn", wrap_pyfunction!(my_fn, gil).unwrap().deref()), - ("MyClass", gil.get_type::()), + ( + "my_fn", + wrap_pyfunction!(my_fn, gil).unwrap().as_borrowed().as_any(), + ), + ("MyClass", gil.get_type_bound::().as_any()), ] .into_py_dict_bound(gil); py_run!(gil, *locals, &handle_windows(test)); @@ -286,7 +289,7 @@ fn test_async_method_receiver() { assert False assert asyncio.run(coro3) == 1 "#; - let locals = [("Counter", gil.get_type::())].into_py_dict_bound(gil); + let locals = [("Counter", gil.get_type_bound::())].into_py_dict_bound(gil); py_run!(gil, *locals, test); }) } diff --git a/tests/test_enum.rs b/tests/test_enum.rs index 33e94c24..d73316e5 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::(); + let my_enum = py.get_type_bound::(); 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::(); + let mynum = py.get_type_bound::(); 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::(); + let mynum = py.get_type_bound::(); py_run!(py, f mynum, "f(mynum.OtherVariant)") }) @@ -83,7 +83,7 @@ enum CustomDiscriminant { fn test_custom_discriminant() { Python::with_gil(|py| { #[allow(non_snake_case)] - let CustomDiscriminant = py.get_type::(); + let CustomDiscriminant = py.get_type_bound::(); let one = Py::new(py, CustomDiscriminant::One).unwrap(); let two = Py::new(py, CustomDiscriminant::Two).unwrap(); py_run!(py, CustomDiscriminant one two, r#" @@ -204,7 +204,7 @@ enum RenameAllVariantsEnum { #[test] fn test_renaming_all_enum_variants() { Python::with_gil(|py| { - let enum_obj = py.get_type::(); + let enum_obj = py.get_type_bound::(); 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!( diff --git a/tests/test_gc.rs b/tests/test_gc.rs index 7ed39436..9e236a27 100644 --- a/tests/test_gc.rs +++ b/tests/test_gc.rs @@ -211,11 +211,11 @@ fn inheritance_with_new_methods_with_drop() { let drop_called2 = Arc::new(AtomicBool::new(false)); Python::with_gil(|py| { - let _typebase = py.get_type::(); - let typeobj = py.get_type::(); + let _typebase = py.get_type_bound::(); + let typeobj = py.get_type_bound::(); let inst = typeobj.call((), None).unwrap(); - let obj: &PyCell = inst.downcast().unwrap(); + let obj = inst.downcast::().unwrap(); let mut obj_ref_mut = obj.borrow_mut(); obj_ref_mut.data = Some(Arc::clone(&drop_called1)); let base: &mut BaseClassWithDrop = obj_ref_mut.as_mut(); @@ -255,8 +255,8 @@ fn gc_during_borrow() { Python::with_gil(|py| { unsafe { // get the traverse function - let ty = py.get_type::().as_type_ptr(); - let traverse = get_type_traverse(ty).unwrap(); + let ty = py.get_type_bound::(); + let traverse = get_type_traverse(ty.as_type_ptr()).unwrap(); // create an object and check that traversing it works normally // when it's not borrowed @@ -303,8 +303,8 @@ impl PartialTraverse { fn traverse_partial() { Python::with_gil(|py| unsafe { // get the traverse function - let ty = py.get_type::().as_type_ptr(); - let traverse = get_type_traverse(ty).unwrap(); + let ty = py.get_type_bound::(); + let traverse = get_type_traverse(ty.as_type_ptr()).unwrap(); // confirm that traversing errors let obj = Py::new(py, PartialTraverse::new(py)).unwrap(); @@ -338,8 +338,8 @@ impl PanickyTraverse { fn traverse_panic() { Python::with_gil(|py| unsafe { // get the traverse function - let ty = py.get_type::().as_type_ptr(); - let traverse = get_type_traverse(ty).unwrap(); + let ty = py.get_type_bound::(); + let traverse = get_type_traverse(ty.as_type_ptr()).unwrap(); // confirm that traversing errors let obj = Py::new(py, PanickyTraverse::new(py)).unwrap(); @@ -361,8 +361,8 @@ impl TriesGILInTraverse { fn tries_gil_in_traverse() { Python::with_gil(|py| unsafe { // get the traverse function - let ty = py.get_type::().as_type_ptr(); - let traverse = get_type_traverse(ty).unwrap(); + let ty = py.get_type_bound::(); + let traverse = get_type_traverse(ty.as_type_ptr()).unwrap(); // confirm that traversing panicks let obj = Py::new(py, TriesGILInTraverse {}).unwrap(); @@ -413,8 +413,8 @@ 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::().as_type_ptr(); - let traverse = get_type_traverse(ty).unwrap(); + let ty = py.get_type_bound::(); + let traverse = get_type_traverse(ty.as_type_ptr()).unwrap(); let cell = PyCell::new(py, HijackedTraverse::new()).unwrap(); let obj = cell.to_object(py); @@ -528,8 +528,8 @@ impl UnsendableTraversal { #[cfg(not(target_arch = "wasm32"))] // We are building wasm Python with pthreads disabled fn unsendable_are_not_traversed_on_foreign_thread() { Python::with_gil(|py| unsafe { - let ty = py.get_type::().as_type_ptr(); - let traverse = get_type_traverse(ty).unwrap(); + let ty = py.get_type_bound::(); + let traverse = get_type_traverse(ty.as_type_ptr()).unwrap(); let obj = Py::new( py, diff --git a/tests/test_getter_setter.rs b/tests/test_getter_setter.rs index b990a82e..1009ce1b 100644 --- a/tests/test_getter_setter.rs +++ b/tests/test_getter_setter.rs @@ -64,7 +64,7 @@ fn class_with_properties() { py_run!(py, inst, "assert inst.get_num() == inst.unwrapped == 42"); py_run!(py, inst, "assert inst.data_list == [42]"); - let d = [("C", py.get_type::())].into_py_dict_bound(py); + let d = [("C", py.get_type_bound::())].into_py_dict_bound(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 cd728c77..af34974c 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::())].into_py_dict_bound(py); + let d = [("SubclassAble", py.get_type_bound::())].into_py_dict_bound(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::(); + let typeobj = py.get_type_bound::(); let inst = typeobj.call((), None).unwrap(); py_run!(py, inst, "assert inst.val1 == 10; assert inst.val2 == 5"); }); @@ -112,16 +112,16 @@ fn mutation_fails() { #[test] fn is_subclass_and_is_instance() { Python::with_gil(|py| { - let sub_ty = py.get_type::(); - let base_ty = py.get_type::(); + let sub_ty = py.get_type_bound::(); + let base_ty = py.get_type_bound::(); assert!(sub_ty.is_subclass_of::().unwrap()); - assert!(sub_ty.is_subclass(base_ty).unwrap()); + assert!(sub_ty.is_subclass(&base_ty).unwrap()); - let obj = PyCell::new(py, SubClass::new()).unwrap(); + let obj = Bound::new(py, SubClass::new()).unwrap().into_any(); assert!(obj.is_instance_of::()); assert!(obj.is_instance_of::()); - assert!(obj.is_instance(sub_ty).unwrap()); - assert!(obj.is_instance(base_ty).unwrap()); + assert!(obj.is_instance(&sub_ty).unwrap()); + assert!(obj.is_instance(&base_ty).unwrap()); }); } @@ -155,7 +155,7 @@ impl SubClass2 { #[test] fn handle_result_in_new() { Python::with_gil(|py| { - let subclass = py.get_type::(); + let subclass = py.get_type_bound::(); py_run!( py, subclass, @@ -274,15 +274,15 @@ mod inheriting_native_type { #[test] fn custom_exception() { Python::with_gil(|py| { - let cls = py.get_type::(); - let dict = [("cls", cls)].into_py_dict_bound(py); + let cls = py.get_type_bound::(); + let dict = [("cls", &cls)].into_py_dict_bound(py); let res = py.run_bound( "e = cls('hello'); assert str(e) == 'hello'; assert e.context == 'Hello :)'; raise e", None, Some(&dict) ); let err = res.unwrap_err(); - assert!(err.matches(py, cls), "{}", err); + assert!(err.matches(py, &cls), "{}", err); // catching the exception in Python also works: py_run!( @@ -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::(); + let SimpleClass = py.get_type_bound::(); py_run!( py, SimpleClass, diff --git a/tests/test_macro_docs.rs b/tests/test_macro_docs.rs index 5e240816..6289626d 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::())].into_py_dict_bound(py); + let d = [("C", py.get_type_bound::())].into_py_dict_bound(py); py_assert!( py, *d, diff --git a/tests/test_macros.rs b/tests/test_macros.rs index c01ba853..0d2b125b 100644 --- a/tests/test_macros.rs +++ b/tests/test_macros.rs @@ -73,7 +73,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::(); + let my_base = py.get_type_bound::(); py_assert!(py, my_base, "my_base.__name__ == 'MyClass'"); let my_func = wrap_pyfunction!(my_function_in_macro, py).unwrap(); @@ -83,7 +83,7 @@ fn test_macro_rules_interactions() { "my_func.__text_signature__ == '(a, b=None, *, c=42)'" ); - let renamed_prop = py.get_type::(); + let renamed_prop = py.get_type_bound::(); py_assert!( py, renamed_prop, diff --git a/tests/test_mapping.rs b/tests/test_mapping.rs index 9a80ab49..06928e74 100644 --- a/tests/test_mapping.rs +++ b/tests/test_mapping.rs @@ -69,7 +69,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::())].into_py_dict_bound(py); + let d = [("Mapping", py.get_type_bound::())].into_py_dict_bound(py); py_run!(py, *d, "m = Mapping(['1', '2', '3'])"); d } diff --git a/tests/test_methods.rs b/tests/test_methods.rs index 2114ead2..96b40174 100644 --- a/tests/test_methods.rs +++ b/tests/test_methods.rs @@ -95,7 +95,7 @@ impl ClassMethod { #[test] fn class_method() { Python::with_gil(|py| { - let d = [("C", py.get_type::())].into_py_dict_bound(py); + let d = [("C", py.get_type_bound::())].into_py_dict_bound(py); py_assert!(py, *d, "C.method() == 'ClassMethod.method()!'"); py_assert!(py, *d, "C().method() == 'ClassMethod.method()!'"); py_assert!( @@ -126,7 +126,7 @@ impl ClassMethodWithArgs { #[test] fn class_method_with_args() { Python::with_gil(|py| { - let d = [("C", py.get_type::())].into_py_dict_bound(py); + let d = [("C", py.get_type_bound::())].into_py_dict_bound(py); py_assert!( py, *d, @@ -157,7 +157,7 @@ fn static_method() { Python::with_gil(|py| { assert_eq!(StaticMethod::method(py), "StaticMethod.method()!"); - let d = [("C", py.get_type::())].into_py_dict_bound(py); + let d = [("C", py.get_type_bound::())].into_py_dict_bound(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.'"); @@ -181,7 +181,7 @@ fn static_method_with_args() { Python::with_gil(|py| { assert_eq!(StaticMethodWithArgs::method(py, 1234), "0x4d2"); - let d = [("C", py.get_type::())].into_py_dict_bound(py); + let d = [("C", py.get_type_bound::())].into_py_dict_bound(py); py_assert!(py, *d, "C.method(1337) == '0x539'"); }); } @@ -679,7 +679,7 @@ impl MethDocs { #[test] fn meth_doc() { Python::with_gil(|py| { - let d = [("C", py.get_type::())].into_py_dict_bound(py); + let d = [("C", py.get_type_bound::())].into_py_dict_bound(py); py_assert!(py, *d, "C.__doc__ == 'A class with \"documentation\".'"); py_assert!( py, @@ -866,7 +866,7 @@ impl FromSequence { #[test] fn test_from_sequence() { Python::with_gil(|py| { - let typeobj = py.get_type::(); + let typeobj = py.get_type_bound::(); py_assert!(py, typeobj, "typeobj(range(0, 4)).numbers == [0, 1, 2, 3]"); }); } @@ -946,7 +946,7 @@ impl r#RawIdents { #[test] fn test_raw_idents() { Python::with_gil(|py| { - let raw_idents_type = py.get_type::(); + let raw_idents_type = py.get_type_bound::(); 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 13baeed3..308220e7 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::(); + let cls = py.get_type_bound::(); 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_no_imports.rs b/tests/test_no_imports.rs index 4abdcdf2..88932ed2 100644 --- a/tests/test_no_imports.rs +++ b/tests/test_no_imports.rs @@ -2,6 +2,8 @@ #![cfg(feature = "macros")] +use pyo3::prelude::PyAnyMethods; + #[pyo3::pyfunction] #[pyo3(name = "identity", signature = (x = None))] fn basic_function(py: pyo3::Python<'_>, x: Option) -> pyo3::PyObject { @@ -91,13 +93,13 @@ impl BasicClass { fn test_basic() { pyo3::Python::with_gil(|py| { let module = pyo3::wrap_pymodule!(basic_module)(py); - let cls = py.get_type::(); + let cls = py.get_type_bound::(); let d = pyo3::types::IntoPyDict::into_py_dict_bound( [ - ("mod", module.as_ref(py).as_ref()), - ("cls", cls.as_ref()), - ("a", cls.call1((8,)).unwrap()), - ("b", cls.call1(("foo",)).unwrap()), + ("mod", module.bind(py).as_any()), + ("cls", &cls), + ("a", &cls.call1((8,)).unwrap()), + ("b", &cls.call1(("foo",)).unwrap()), ], py, ); @@ -144,7 +146,7 @@ impl NewClassMethod { #[test] fn test_new_class_method() { pyo3::Python::with_gil(|py| { - let cls = py.get_type::(); + let cls = py.get_type_bound::(); pyo3::py_run!(py, cls, "assert cls().cls is cls"); }); } diff --git a/tests/test_proto_methods.rs b/tests/test_proto_methods.rs index 3151fbe5..9126555d 100644 --- a/tests/test_proto_methods.rs +++ b/tests/test_proto_methods.rs @@ -672,7 +672,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::(); + let once = py.get_type_bound::(); let source = r#" import asyncio import sys @@ -725,7 +725,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::(); + let once = py.get_type_bound::(); let source = r#" import asyncio import sys @@ -750,7 +750,7 @@ asyncio.run(main()) .as_borrowed(); globals.set_item("Once", once).unwrap(); globals - .set_item("AsyncIterator", py.get_type::()) + .set_item("AsyncIterator", py.get_type_bound::()) .unwrap(); py.run_bound(source, Some(&globals), None) .map_err(|e| e.display(py)) @@ -793,7 +793,7 @@ impl DescrCounter { #[test] fn descr_getset() { Python::with_gil(|py| { - let counter = py.get_type::(); + let counter = py.get_type_bound::(); let source = pyo3::indoc::indoc!( r#" class Class: diff --git a/tests/test_sequence.rs b/tests/test_sequence.rs index f18323db..d73d2d11 100644 --- a/tests/test_sequence.rs +++ b/tests/test_sequence.rs @@ -106,7 +106,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::())].into_py_dict_bound(py); + let d = [("ByteSequence", py.get_type_bound::())].into_py_dict_bound(py); // Though we can construct `s` in Rust, let's test `__new__` works. py_run!(py, *d, "s = ByteSequence([1, 2, 3])"); d @@ -138,7 +138,7 @@ fn test_setitem() { #[test] fn test_delitem() { Python::with_gil(|py| { - let d = [("ByteSequence", py.get_type::())].into_py_dict_bound(py); + let d = [("ByteSequence", py.get_type_bound::())].into_py_dict_bound(py); py_run!( py, @@ -234,7 +234,7 @@ fn test_repeat() { #[test] fn test_inplace_repeat() { Python::with_gil(|py| { - let d = [("ByteSequence", py.get_type::())].into_py_dict_bound(py); + let d = [("ByteSequence", py.get_type_bound::())].into_py_dict_bound(py); py_run!( py, diff --git a/tests/test_static_slots.rs b/tests/test_static_slots.rs index b01c87cd..3c270a31 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::())].into_py_dict_bound(py); + let d = [("Count5", py.get_type_bound::())].into_py_dict_bound(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 208290df..8dcedf80 100644 --- a/tests/test_super.rs +++ b/tests/test_super.rs @@ -44,7 +44,7 @@ impl SubClass { #[test] fn test_call_super_method() { Python::with_gil(|py| { - let cls = py.get_type::(); + let cls = py.get_type_bound::(); pyo3::py_run!( py, cls, diff --git a/tests/test_text_signature.rs b/tests/test_text_signature.rs index 9056ca21..b72ad2a2 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::(); + let typeobj = py.get_type_bound::(); 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::(); + let typeobj = py.get_type_bound::(); 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::(); + let typeobj = py.get_type_bound::(); 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::(); + let typeobj = py.get_type_bound::(); py_assert!(py, typeobj, "typeobj.__doc__ == 'docs line1\\ndocs line2'"); py_assert!( @@ -238,7 +238,7 @@ fn test_auto_test_signature_method() { } Python::with_gil(|py| { - let cls = py.get_type::(); + let cls = py.get_type_bound::(); #[cfg(any(not(Py_LIMITED_API), Py_3_10))] py_assert!(py, cls, "cls.__text_signature__ == '(a, b, c)'"); py_assert!( @@ -323,7 +323,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::(); + let cls = py.get_type_bound::(); 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"); @@ -383,7 +383,7 @@ fn test_methods() { } Python::with_gil(|py| { - let typeobj = py.get_type::(); + let typeobj = py.get_type_bound::(); py_assert!( py, @@ -424,7 +424,7 @@ fn test_raw_identifiers() { } Python::with_gil(|py| { - let typeobj = py.get_type::(); + let typeobj = py.get_type_bound::(); py_assert!(py, typeobj, "typeobj.__text_signature__ == '()'"); diff --git a/tests/test_variable_arguments.rs b/tests/test_variable_arguments.rs index a1f8bb35..8d3cd5d3 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::(); + let my_obj = py.get_type_bound::(); 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::(); + let my_obj = py.get_type_bound::(); 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!(