diff --git a/src/types/dict.rs b/src/types/dict.rs index 74e2d79adb5..80d187c175c 100644 --- a/src/types/dict.rs +++ b/src/types/dict.rs @@ -591,14 +591,14 @@ mod tests { fn test_set_item_refcnt() { Python::with_gil(|py| { let cnt; + let obj = py.eval("object()", None, None).unwrap(); { let _pool = unsafe { crate::GILPool::new() }; - let none = py.None(); - cnt = none.get_refcnt(py); - let _dict = [(10, none)].into_py_dict(py); + cnt = obj.get_refcnt(); + let _dict = [(10, obj)].into_py_dict(py); } { - assert_eq!(cnt, py.None().get_refcnt(py)); + assert_eq!(cnt, obj.get_refcnt()); } }); } diff --git a/src/types/iterator.rs b/src/types/iterator.rs index 71ca5d305b4..7b411bde765 100644 --- a/src/types/iterator.rs +++ b/src/types/iterator.rs @@ -155,31 +155,30 @@ mod tests { #[test] fn iter_item_refcnt() { Python::with_gil(|py| { - let obj; - let none; let count; - { + let obj = py.eval("object()", None, None).unwrap(); + let list = { let _pool = unsafe { GILPool::new() }; - let l = PyList::empty(py); - none = py.None(); - l.append(10).unwrap(); - l.append(&none).unwrap(); - count = none.get_refcnt(py); - obj = l.to_object(py); - } + let list = PyList::empty(py); + list.append(10).unwrap(); + list.append(obj).unwrap(); + count = obj.get_refcnt(); + list.to_object(py) + }; { let _pool = unsafe { GILPool::new() }; - let inst = obj.as_ref(py); + let inst = list.as_ref(py); let mut it = inst.iter().unwrap(); assert_eq!( 10_i32, it.next().unwrap().unwrap().extract::<'_, i32>().unwrap() ); - assert!(it.next().unwrap().unwrap().is_none()); + assert!(it.next().unwrap().unwrap().is(obj)); + assert!(it.next().is_none()); } - assert_eq!(count, none.get_refcnt(py)); + assert_eq!(count, obj.get_refcnt()); }); } diff --git a/src/types/list.rs b/src/types/list.rs index e86086467f9..91de4eb418b 100644 --- a/src/types/list.rs +++ b/src/types/list.rs @@ -395,18 +395,18 @@ mod tests { #[test] fn test_set_item_refcnt() { Python::with_gil(|py| { + let obj = py.eval("object()", None, None).unwrap(); let cnt; { let _pool = unsafe { crate::GILPool::new() }; let v = vec![2]; let ob = v.to_object(py); let list: &PyList = ob.downcast(py).unwrap(); - let none = py.None(); - cnt = none.get_refcnt(py); - list.set_item(0, none).unwrap(); + cnt = obj.get_refcnt(); + list.set_item(0, obj).unwrap(); } - assert_eq!(cnt, py.None().get_refcnt(py)); + assert_eq!(cnt, obj.get_refcnt()); }); } @@ -431,15 +431,15 @@ mod tests { fn test_insert_refcnt() { Python::with_gil(|py| { let cnt; + let obj = py.eval("object()", None, None).unwrap(); { let _pool = unsafe { crate::GILPool::new() }; let list = PyList::empty(py); - let none = py.None(); - cnt = none.get_refcnt(py); - list.insert(0, none).unwrap(); + cnt = obj.get_refcnt(); + list.insert(0, obj).unwrap(); } - assert_eq!(cnt, py.None().get_refcnt(py)); + assert_eq!(cnt, obj.get_refcnt()); }); } @@ -457,14 +457,14 @@ mod tests { fn test_append_refcnt() { Python::with_gil(|py| { let cnt; + let obj = py.eval("object()", None, None).unwrap(); { let _pool = unsafe { crate::GILPool::new() }; let list = PyList::empty(py); - let none = py.None(); - cnt = none.get_refcnt(py); - list.append(none).unwrap(); + cnt = obj.get_refcnt(); + list.append(obj).unwrap(); } - assert_eq!(cnt, py.None().get_refcnt(py)); + assert_eq!(cnt, obj.get_refcnt()); }); }