diff --git a/src/noargs.rs b/src/noargs.rs index d0e010ba..bc4d2428 100644 --- a/src/noargs.rs +++ b/src/noargs.rs @@ -61,11 +61,3 @@ impl IntoPyDictPointer for NoArgs { std::ptr::null_mut() } } - -/// Converts `()` to an null pointer. -impl IntoPyDictPointer for () { - - fn into_dict_ptr(self, _: Python) -> *mut ffi::PyObject { - std::ptr::null_mut() - } -} diff --git a/src/objectprotocol.rs b/src/objectprotocol.rs index 8f39aa3d..4b482a9b 100644 --- a/src/objectprotocol.rs +++ b/src/objectprotocol.rs @@ -468,6 +468,7 @@ mod test { use conversion::{ToPyObject, PyTryFrom}; use objects::PyString; use super::*; + use noargs::NoArgs; #[test] fn test_debug_string() { @@ -493,7 +494,7 @@ mod test { let py = gil.python(); let a = py.eval("42", None, None).unwrap(); a.call_method0("__str__").unwrap(); // ok - assert!(a.call_method("nonexistent_method", (1,), ()).is_err()); + assert!(a.call_method("nonexistent_method", (1,), NoArgs).is_err()); assert!(a.call_method0("nonexistent_method").is_err()); assert!(a.call_method1("nonexistent_method", (1,)).is_err()); } diff --git a/src/objects/dict.rs b/src/objects/dict.rs index 3c76e47d..93bbbb6b 100644 --- a/src/objects/dict.rs +++ b/src/objects/dict.rs @@ -243,43 +243,6 @@ where } } -impl IntoPyDictPointer for (K, V) { - default fn into_dict_ptr(self, py: Python) -> *mut ffi::PyObject { - let dict = PyDict::new(py); - dict.set_item(self.0, self.1).expect("Failed to set_item on dict"); - dict.into_ptr() - } -} - -macro_rules! dict_conversion ({$length:expr,$(($refN:ident, $n:tt, $T1:ident, $T2:ident)),+} => { - impl<$($T1: ToPyObject, $T2: ToPyObject),+> IntoPyDictPointer for ($(($T1,$T2),)+) { - fn into_dict_ptr(self, py: Python) -> *mut ffi::PyObject { - let dict = PyDict::new(py); - $(dict.set_item(self.$n.0, self.$n.1).expect("Failed to set_item on dict");)+; - dict.into_ptr() - } - } -}); - -dict_conversion!(1, (ref0, 0, A1, A2)); -dict_conversion!(2, (ref0, 0, A1, A2), (ref1, 1, B1, B2)); -dict_conversion!(3, (ref0, 0, A1, A2), (ref1, 1, B1, B2), (ref2, 2, C1, C2)); -dict_conversion!(4, (ref0, 0, A1, A2), (ref1, 1, B1, B2), (ref2, 2, C1, C2), - (ref3, 3, D1, D2)); -dict_conversion!(5, (ref0, 0, A1, A2), (ref1, 1, B1, B2), (ref2, 2, C1, C2), - (ref3, 3, D1, D2), (ref4, 4, E1, E2)); -dict_conversion!(6, (ref0, 0, A1, A2), (ref1, 1, B1, B2), (ref2, 2, C1, C2), - (ref3, 3, D1, D2), (ref4, 4, E1, E2), (ref5, 5, F1, F2)); -dict_conversion!(7, (ref0, 0, A1, A2), (ref1, 1, B1, B2), (ref2, 2, C1, C2), - (ref3, 3, D1, D2), (ref4, 4, E1, E2), (ref5, 5, F1, F2), (ref6, 6, G1, G2)); -dict_conversion!(8, (ref0, 0, A1, A2), (ref1, 1, B1, B2), (ref2, 2, C1, C2), - (ref3, 3, D1, D2), (ref4, 4, E1, E2), (ref5, 5, F1, F2), (ref6, 6, G1, G2), - (ref7, 7, H1, H2)); -dict_conversion!(9, (ref0, 0, A1, A2), (ref1, 1, B1, B2), (ref2, 2, C1, C2), - (ref3, 3, D1, D2), (ref4, 4, E1, E2), (ref5, 5, F1, F2), (ref6, 6, G1, G2), - (ref7, 7, H1, H2), (ref8, 8, I1, I2)); - - #[cfg(test)] mod test { use std::collections::{BTreeMap, HashMap}; @@ -627,38 +590,4 @@ mod test { assert!(py_map.len() == 3); assert!(py_map.get_item("b").unwrap().extract::().unwrap() == 2); } - - #[test] - fn test_tuple_into_dict() { - let gil = Python::acquire_gil(); - let py = gil.python(); - - let m = ((1, 1),).into_dict_ptr(py); - let ob = unsafe{PyObject::from_owned_ptr(py, m)}; - let py_map = ::try_from(ob.as_ref(py)).unwrap(); - - assert!(py_map.len() == 1); - assert!( py_map.get_item(1).unwrap().extract::().unwrap() == 1); - - let m = ((1, 1), (2, 3)).into_dict_ptr(py); - let ob = unsafe{PyObject::from_owned_ptr(py, m)}; - let py_map = ::try_from(ob.as_ref(py)).unwrap(); - - assert!(py_map.len() == 2); - assert!(py_map.get_item(1).unwrap().extract::().unwrap() == 1); - assert!(py_map.get_item(2).unwrap().extract::().unwrap() == 3); - } - - #[test] - fn test_simple_tuple_into_dict() { - let gil = Python::acquire_gil(); - let py = gil.python(); - - let m = (1, 1).into_dict_ptr(py); - let ob = unsafe{PyObject::from_owned_ptr(py, m)}; - let py_map = ::try_from(ob.as_ref(py)).unwrap(); - - assert!(py_map.len() == 1); - assert!(py_map.get_item(1).unwrap().extract::().unwrap() == 1); - } }