From c886127f4a864004ebc1e4b44b661f60daf0c916 Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Tue, 18 Jun 2024 06:21:10 +0100 Subject: [PATCH] fixup --- pytests/src/misc.rs | 7 +++++-- src/types/boolobject.rs | 6 ++++-- src/types/typeobject.rs | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pytests/src/misc.rs b/pytests/src/misc.rs index cd75de232ec..ed9c9333ec2 100644 --- a/pytests/src/misc.rs +++ b/pytests/src/misc.rs @@ -1,4 +1,7 @@ -use pyo3::{prelude::*, types::PyDict}; +use pyo3::{ + prelude::*, + types::{PyDict, PyString}, +}; #[pyfunction] fn issue_219() { @@ -7,7 +10,7 @@ fn issue_219() { } #[pyfunction] -fn get_type_fully_qualified_name(obj: &Bound<'_, PyAny>) -> PyResult { +fn get_type_fully_qualified_name<'py>(obj: &Bound<'py, PyAny>) -> PyResult> { obj.get_type().fully_qualified_name() } diff --git a/src/types/boolobject.rs b/src/types/boolobject.rs index d8d27ebcc72..04c1fd4c113 100644 --- a/src/types/boolobject.rs +++ b/src/types/boolobject.rs @@ -111,13 +111,15 @@ impl FromPyObject<'_> for bool { Err(err) => err, }; - if { + let is_numpy_bool = { let ty = obj.get_type(); ty.module().map_or(false, |module| module == "numpy") && ty .name() .map_or(false, |name| name == "bool_" || name == "bool") - } { + }; + + if is_numpy_bool { let missing_conversion = |obj: &Bound<'_, PyAny>| { PyTypeError::new_err(format!( "object of type '{}' does not define a '__bool__' conversion", diff --git a/src/types/typeobject.rs b/src/types/typeobject.rs index f11e251b3bb..a8913a6888f 100644 --- a/src/types/typeobject.rs +++ b/src/types/typeobject.rs @@ -74,13 +74,13 @@ impl PyType { /// Gets the name of the `PyType`. Equivalent to `self.__name__` in Python. pub fn name(&self) -> PyResult<&PyString> { - self.as_borrowed().name().map(Bound::into_ref) + self.as_borrowed().name().map(Bound::into_gil_ref) } /// Gets the [qualified name](https://docs.python.org/3/glossary.html#term-qualified-name) of the `PyType`. /// Equivalent to `self.__qualname__` in Python. pub fn qualname(&self) -> PyResult<&PyString> { - self.as_borrowed().qualname().map(Bound::into_ref) + self.as_borrowed().qualname().map(Bound::into_gil_ref) } // `module` and `fully_qualified_name` intentionally omitted