Skip to content

Commit

Permalink
fix weakref proxy tests on free-threaded build (#4460)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoldbaum committed Aug 20, 2024
1 parent 06df472 commit 4fb9b86
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/types/weakref/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,12 @@ mod tests {
mod python_class {
use super::*;
use crate::ffi;
use crate::{py_result_ext::PyResultExt, types::PyType};
use crate::{py_result_ext::PyResultExt, types::PyDict, types::PyType};

fn get_type(py: Python<'_>) -> PyResult<Bound<'_, PyType>> {
py.run(ffi::c_str!("class A:\n pass\n"), None, None)?;
py.eval(ffi::c_str!("A"), None, None)
let globals = PyDict::new(py);
py.run(ffi::c_str!("class A:\n pass\n"), Some(&globals), None)?;
py.eval(ffi::c_str!("A"), Some(&globals), None)
.downcast_into::<PyType>()
}

Expand All @@ -262,10 +263,7 @@ mod tests {
format!("<class {}>", CLASS_NAME)
);

assert_eq!(
reference.getattr("__class__")?.to_string(),
"<class '__main__.A'>"
);
assert_eq!(reference.getattr("__class__")?.to_string(), "<class 'A'>");
#[cfg(not(Py_LIMITED_API))]
check_repr(&reference, &object, Some("A"))?;

Expand Down Expand Up @@ -782,15 +780,16 @@ mod tests {
mod python_class {
use super::*;
use crate::ffi;
use crate::{py_result_ext::PyResultExt, types::PyType};
use crate::{py_result_ext::PyResultExt, types::PyDict, types::PyType};

fn get_type(py: Python<'_>) -> PyResult<Bound<'_, PyType>> {
let globals = PyDict::new(py);
py.run(
ffi::c_str!("class A:\n def __call__(self):\n return 'This class is callable!'\n"),
None,
Some(&globals),
None,
)?;
py.eval(ffi::c_str!("A"), None, None)
py.eval(ffi::c_str!("A"), Some(&globals), None)
.downcast_into::<PyType>()
}

Expand All @@ -806,10 +805,7 @@ mod tests {
#[cfg(not(Py_LIMITED_API))]
assert_eq!(reference.get_type().to_string(), CLASS_NAME);

assert_eq!(
reference.getattr("__class__")?.to_string(),
"<class '__main__.A'>"
);
assert_eq!(reference.getattr("__class__")?.to_string(), "<class 'A'>");
#[cfg(not(Py_LIMITED_API))]
check_repr(&reference, &object, Some("A"))?;

Expand Down

0 comments on commit 4fb9b86

Please sign in to comment.