diff --git a/CHANGELOG.md b/CHANGELOG.md index 706b5e73..359bf6c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed + * Slowly removing specialization uses * All exceptions are consturcted with `py_err` instead of `new`, as they return `PyErr` and not `Self`. * `as_mut` and friends take and `&mut self` instead of `&self` + * `ObjectProtocol::call` now takes an `Option` for the kwargs instead of an `IntoPyDictPointer`. + * `IntoPyDictPointer` was replace by `IntoPyDict` which doesn't convert `PyDict` itself anymore and returns a `PyDict` instead of `*mut PyObject`. ### Fixed diff --git a/guide/src/conversions.md b/guide/src/conversions.md index fddcbf86..04e67624 100644 --- a/guide/src/conversions.md +++ b/guide/src/conversions.md @@ -76,11 +76,8 @@ fn main() { } ``` -`kwargs` argument is generate over -[`IntoPyDictPointer`][IntoPyDictPointer] trait. `HashMap` or `BTreeMap` could be used as -keyword arguments. rust tuple with up to 10 elements where each element is tuple with size 2 -could be used as kwargs as well. Or `NoArgs` object can be used to indicate that -no keywords arguments are provided. +`kwargs` can by `None` or `Some(PyDict)`. You can use the +[`IntoPyDict`][IntoPyDict] trait to convert other dict-like containers, e.g. `HashMap`, `BTreeMap` as well as tuples with up to 10 elements and `Vec`s where each element is a two element tuple. ```rust extern crate pyo3; @@ -130,4 +127,4 @@ TODO [IntoPyTuple]: https://docs.rs/pyo3/0.2.7/trait.IntoPyTuple.html [PyTuple]: https://docs.rs/pyo3/0.2.7/struct.PyTuple.html [ObjectProtocol]: https://docs.rs/pyo3/0.2.7/trait.ObjectProtocol.html -[IntoPyDictPointer]: https://docs.rs/pyo3/0.2.7/trait.IntoPyDictPointer.html +[IntoPyDict]: https://docs.rs/pyo3/0.2.7/trait.IntoPyDict.html diff --git a/src/buffer.rs b/src/buffer.rs index db1ed809..9d38fb08 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -720,7 +720,7 @@ mod test { let array = py .import("array") .unwrap() - .call_method("array", ("f", (1.0, 1.5, 2.0, 2.5)), ::NoArgs) + .call_method("array", ("f", (1.0, 1.5, 2.0, 2.5)), None) .unwrap(); let buffer = PyBuffer::get(py, array.into()).unwrap(); assert_eq!(buffer.dimensions(), 1); diff --git a/src/class/async.rs b/src/class/async.rs index 6363885a..16835fd2 100644 --- a/src/class/async.rs +++ b/src/class/async.rs @@ -91,24 +91,18 @@ pub trait PyAsyncAexitProtocol<'p>: PyAsyncProtocol<'p> { #[cfg(Py_3)] #[doc(hidden)] pub trait PyAsyncProtocolImpl { - fn tp_as_async() -> Option; - - fn methods() -> Vec; -} - -#[cfg(Py_3)] -impl PyAsyncProtocolImpl for T { - #[inline] - default fn tp_as_async() -> Option { + fn tp_as_async() -> Option { None } - #[inline] - default fn methods() -> Vec { + fn methods() -> Vec { Vec::new() } } +#[cfg(Py_3)] +impl PyAsyncProtocolImpl for T {} + #[cfg(Py_3)] impl<'p, T> PyAsyncProtocolImpl for T where @@ -139,19 +133,13 @@ where } trait PyAsyncAwaitProtocolImpl { - fn am_await() -> Option; -} - -impl<'p, T> PyAsyncAwaitProtocolImpl for T -where - T: PyAsyncProtocol<'p>, -{ - #[inline] - default fn am_await() -> Option { + fn am_await() -> Option { None } } +impl<'p, T> PyAsyncAwaitProtocolImpl for T where T: PyAsyncProtocol<'p> {} + impl PyAsyncAwaitProtocolImpl for T where T: for<'p> PyAsyncAwaitProtocol<'p>, @@ -168,19 +156,13 @@ where } trait PyAsyncAiterProtocolImpl { - fn am_aiter() -> Option; -} - -impl<'p, T> PyAsyncAiterProtocolImpl for T -where - T: PyAsyncProtocol<'p>, -{ - #[inline] - default fn am_aiter() -> Option { + fn am_aiter() -> Option { None } } +impl<'p, T> PyAsyncAiterProtocolImpl for T where T: PyAsyncProtocol<'p> {} + impl PyAsyncAiterProtocolImpl for T where T: for<'p> PyAsyncAiterProtocol<'p>, @@ -197,19 +179,13 @@ where } trait PyAsyncAnextProtocolImpl { - fn am_anext() -> Option; -} - -impl<'p, T> PyAsyncAnextProtocolImpl for T -where - T: PyAsyncProtocol<'p>, -{ - #[inline] - default fn am_anext() -> Option { + fn am_anext() -> Option { None } } +impl<'p, T> PyAsyncAnextProtocolImpl for T where T: PyAsyncProtocol<'p> {} + #[cfg(Py_3)] mod anext { use super::{PyAsyncAnextProtocol, PyAsyncAnextProtocolImpl}; @@ -260,29 +236,17 @@ mod anext { } trait PyAsyncAenterProtocolImpl { - fn __aenter__() -> Option; -} - -impl<'p, T> PyAsyncAenterProtocolImpl for T -where - T: PyAsyncProtocol<'p>, -{ - #[inline] - default fn __aenter__() -> Option { + fn __aenter__() -> Option { None } } +impl<'p, T> PyAsyncAenterProtocolImpl for T where T: PyAsyncProtocol<'p> {} + trait PyAsyncAexitProtocolImpl { - fn __aexit__() -> Option; -} - -impl<'p, T> PyAsyncAexitProtocolImpl for T -where - T: PyAsyncProtocol<'p>, -{ - #[inline] - default fn __aexit__() -> Option { + fn __aexit__() -> Option { None } } + +impl<'p, T> PyAsyncAexitProtocolImpl for T where T: PyAsyncProtocol<'p> {} diff --git a/src/class/basic.rs b/src/class/basic.rs index 2f691018..d291dae2 100644 --- a/src/class/basic.rs +++ b/src/class/basic.rs @@ -150,26 +150,21 @@ pub trait PyObjectRichcmpProtocol<'p>: PyObjectProtocol<'p> { #[doc(hidden)] pub trait PyObjectProtocolImpl { - fn methods() -> Vec; - fn tp_as_object(type_object: &mut ffi::PyTypeObject); - fn nb_bool_fn() -> Option; -} - -impl PyObjectProtocolImpl for T { - default fn methods() -> Vec { + fn methods() -> Vec { Vec::new() } - default fn tp_as_object(_type_object: &mut ffi::PyTypeObject) {} - default fn nb_bool_fn() -> Option { + fn tp_as_object(_type_object: &mut ffi::PyTypeObject) {} + fn nb_bool_fn() -> Option { None } } +impl PyObjectProtocolImpl for T {} + impl<'p, T> PyObjectProtocolImpl for T where T: PyObjectProtocol<'p>, { - #[inline] fn methods() -> Vec { let mut methods = Vec::new(); @@ -203,22 +198,15 @@ where } trait PyObjectGetAttrProtocolImpl { - fn tp_getattro() -> Option; -} -impl<'p, T> PyObjectGetAttrProtocolImpl for T -where - T: PyObjectProtocol<'p>, -{ - #[inline] - default fn tp_getattro() -> Option { + fn tp_getattro() -> Option { None } } +impl<'p, T> PyObjectGetAttrProtocolImpl for T where T: PyObjectProtocol<'p> {} impl PyObjectGetAttrProtocolImpl for T where T: for<'p> PyObjectGetAttrProtocol<'p>, { - #[inline] fn tp_getattro() -> Option { py_binary_func!( PyObjectGetAttrProtocol, @@ -230,45 +218,31 @@ where } trait PyObjectSetAttrProtocolImpl { - fn tp_setattro() -> Option; -} - -impl<'p, T> PyObjectSetAttrProtocolImpl for T -where - T: PyObjectProtocol<'p>, -{ - #[inline] - default fn tp_setattro() -> Option { + fn tp_setattro() -> Option { None } } + +impl<'p, T> PyObjectSetAttrProtocolImpl for T where T: PyObjectProtocol<'p> {} impl PyObjectSetAttrProtocolImpl for T where T: for<'p> PyObjectSetAttrProtocol<'p>, { - #[inline] fn tp_setattro() -> Option { py_func_set!(PyObjectSetAttrProtocol, T::__setattr__) } } trait PyObjectDelAttrProtocolImpl { - fn tp_delattro() -> Option; -} -impl<'p, T> PyObjectDelAttrProtocolImpl for T -where - T: PyObjectProtocol<'p>, -{ - #[inline] - default fn tp_delattro() -> Option { + fn tp_delattro() -> Option { None } } +impl<'p, T> PyObjectDelAttrProtocolImpl for T where T: PyObjectProtocol<'p> {} impl PyObjectDelAttrProtocolImpl for T where T: for<'p> PyObjectDelAttrProtocol<'p>, { - #[inline] default fn tp_delattro() -> Option { py_func_del!(PyObjectDelAttrProtocol, T::__delattr__) } @@ -277,33 +251,27 @@ impl PyObjectDelAttrProtocolImpl for T where T: for<'p> PyObjectSetAttrProtocol<'p> + for<'p> PyObjectDelAttrProtocol<'p>, { - #[inline] fn tp_delattro() -> Option { py_func_set_del!( PyObjectSetAttrProtocol, PyObjectDelAttrProtocol, - T::__setattr__ / __delattr__ + T, + __setattr__, + __delattr__ ) } } trait PyObjectStrProtocolImpl { - fn tp_str() -> Option; -} -impl<'p, T> PyObjectStrProtocolImpl for T -where - T: PyObjectProtocol<'p>, -{ - #[inline] - default fn tp_str() -> Option { + fn tp_str() -> Option { None } } +impl<'p, T> PyObjectStrProtocolImpl for T where T: PyObjectProtocol<'p> {} impl PyObjectStrProtocolImpl for T where T: for<'p> PyObjectStrProtocol<'p>, { - #[inline] fn tp_str() -> Option { py_unary_func!( PyObjectStrProtocol, @@ -315,22 +283,15 @@ where } trait PyObjectReprProtocolImpl { - fn tp_repr() -> Option; -} -impl<'p, T> PyObjectReprProtocolImpl for T -where - T: PyObjectProtocol<'p>, -{ - #[inline] - default fn tp_repr() -> Option { + fn tp_repr() -> Option { None } } +impl<'p, T> PyObjectReprProtocolImpl for T where T: PyObjectProtocol<'p> {} impl PyObjectReprProtocolImpl for T where T: for<'p> PyObjectReprProtocol<'p>, { - #[inline] fn tp_repr() -> Option { py_unary_func!( PyObjectReprProtocol, @@ -343,63 +304,38 @@ where #[doc(hidden)] pub trait PyObjectFormatProtocolImpl { - fn __format__() -> Option; -} -impl<'p, T> PyObjectFormatProtocolImpl for T -where - T: PyObjectProtocol<'p>, -{ - #[inline] - default fn __format__() -> Option { + fn __format__() -> Option { None } } +impl<'p, T> PyObjectFormatProtocolImpl for T where T: PyObjectProtocol<'p> {} #[doc(hidden)] pub trait PyObjectBytesProtocolImpl { - fn __bytes__() -> Option; -} -impl<'p, T> PyObjectBytesProtocolImpl for T -where - T: PyObjectProtocol<'p>, -{ - #[inline] - default fn __bytes__() -> Option { + fn __bytes__() -> Option { None } } +impl<'p, T> PyObjectBytesProtocolImpl for T where T: PyObjectProtocol<'p> {} #[doc(hidden)] pub trait PyObjectUnicodeProtocolImpl { - fn __unicode__() -> Option; -} -impl<'p, T> PyObjectUnicodeProtocolImpl for T -where - T: PyObjectProtocol<'p>, -{ - #[inline] - default fn __unicode__() -> Option { + fn __unicode__() -> Option { None } } +impl<'p, T> PyObjectUnicodeProtocolImpl for T where T: PyObjectProtocol<'p> {} trait PyObjectHashProtocolImpl { - fn tp_hash() -> Option; -} -impl<'p, T> PyObjectHashProtocolImpl for T -where - T: PyObjectProtocol<'p>, -{ - #[inline] - default fn tp_hash() -> Option { + fn tp_hash() -> Option { None } } +impl<'p, T> PyObjectHashProtocolImpl for T where T: PyObjectProtocol<'p> {} impl PyObjectHashProtocolImpl for T where T: for<'p> PyObjectHashProtocol<'p>, { - #[inline] fn tp_hash() -> Option { py_unary_func!( PyObjectHashProtocol, @@ -412,22 +348,15 @@ where } trait PyObjectBoolProtocolImpl { - fn nb_bool() -> Option; -} -impl<'p, T> PyObjectBoolProtocolImpl for T -where - T: PyObjectProtocol<'p>, -{ - #[inline] - default fn nb_bool() -> Option { + fn nb_bool() -> Option { None } } +impl<'p, T> PyObjectBoolProtocolImpl for T where T: PyObjectProtocol<'p> {} impl PyObjectBoolProtocolImpl for T where T: for<'p> PyObjectBoolProtocol<'p>, { - #[inline] fn nb_bool() -> Option { py_unary_func!( PyObjectBoolProtocol, @@ -440,22 +369,15 @@ where } trait PyObjectRichcmpProtocolImpl { - fn tp_richcompare() -> Option; -} -impl<'p, T> PyObjectRichcmpProtocolImpl for T -where - T: PyObjectProtocol<'p>, -{ - #[inline] - default fn tp_richcompare() -> Option { + fn tp_richcompare() -> Option { None } } +impl<'p, T> PyObjectRichcmpProtocolImpl for T where T: PyObjectProtocol<'p> {} impl PyObjectRichcmpProtocolImpl for T where T: for<'p> PyObjectRichcmpProtocol<'p>, { - #[inline] fn tp_richcompare() -> Option { unsafe extern "C" fn wrap( slf: *mut ffi::PyObject, diff --git a/src/class/buffer.rs b/src/class/buffer.rs index d6f8a438..764902f1 100644 --- a/src/class/buffer.rs +++ b/src/class/buffer.rs @@ -42,15 +42,13 @@ pub trait PyBufferReleaseBufferProtocol<'p>: PyBufferProtocol<'p> { #[doc(hidden)] pub trait PyBufferProtocolImpl { - fn tp_as_buffer() -> Option; -} - -impl PyBufferProtocolImpl for T { - default fn tp_as_buffer() -> Option { + fn tp_as_buffer() -> Option { None } } +impl PyBufferProtocolImpl for T {} + impl<'p, T> PyBufferProtocolImpl for T where T: PyBufferProtocol<'p>, @@ -67,19 +65,13 @@ where } trait PyBufferGetBufferProtocolImpl { - fn cb_bf_getbuffer() -> Option; -} - -impl<'p, T> PyBufferGetBufferProtocolImpl for T -where - T: PyBufferProtocol<'p>, -{ - #[inline] - default fn cb_bf_getbuffer() -> Option { + fn cb_bf_getbuffer() -> Option { None } } +impl<'p, T> PyBufferGetBufferProtocolImpl for T where T: PyBufferProtocol<'p> {} + impl PyBufferGetBufferProtocolImpl for T where T: for<'p> PyBufferGetBufferProtocol<'p>, diff --git a/src/class/context.rs b/src/class/context.rs index cec618a2..7be87321 100644 --- a/src/class/context.rs +++ b/src/class/context.rs @@ -46,16 +46,13 @@ pub trait PyContextExitProtocol<'p>: PyContextProtocol<'p> { #[doc(hidden)] pub trait PyContextProtocolImpl { - fn methods() -> Vec; -} - -impl PyContextProtocolImpl for T { - #[inline] - default fn methods() -> Vec { + fn methods() -> Vec { Vec::new() } } +impl PyContextProtocolImpl for T {} + impl<'p, T> PyContextProtocolImpl for T where T: PyContextProtocol<'p>, @@ -77,30 +74,18 @@ where #[doc(hidden)] pub trait PyContextEnterProtocolImpl { - fn __enter__() -> Option; -} - -impl<'p, T> PyContextEnterProtocolImpl for T -where - T: PyContextProtocol<'p>, -{ - #[inline] - default fn __enter__() -> Option { + fn __enter__() -> Option { None } } +impl<'p, T> PyContextEnterProtocolImpl for T where T: PyContextProtocol<'p> {} + #[doc(hidden)] pub trait PyContextExitProtocolImpl { - fn __exit__() -> Option; -} - -impl<'p, T> PyContextExitProtocolImpl for T -where - T: PyContextProtocol<'p>, -{ - #[inline] - default fn __exit__() -> Option { + fn __exit__() -> Option { None } } + +impl<'p, T> PyContextExitProtocolImpl for T where T: PyContextProtocol<'p> {} diff --git a/src/class/descr.rs b/src/class/descr.rs index 93fac3e7..724e2a57 100644 --- a/src/class/descr.rs +++ b/src/class/descr.rs @@ -71,16 +71,12 @@ pub trait PyDescrSetNameProtocol<'p>: PyDescrProtocol<'p> { } trait PyDescrGetProtocolImpl { - fn tp_descr_get() -> Option; -} -impl<'p, T> PyDescrGetProtocolImpl for T -where - T: PyDescrProtocol<'p>, -{ - default fn tp_descr_get() -> Option { + fn tp_descr_get() -> Option { None } } +impl<'p, T> PyDescrGetProtocolImpl for T where T: PyDescrProtocol<'p> {} + impl PyDescrGetProtocolImpl for T where T: for<'p> PyDescrGetProtocol<'p>, @@ -94,17 +90,13 @@ where ) } } + trait PyDescrSetProtocolImpl { - fn tp_descr_set() -> Option; -} -impl<'p, T> PyDescrSetProtocolImpl for T -where - T: PyDescrProtocol<'p>, -{ - default fn tp_descr_set() -> Option { + fn tp_descr_set() -> Option { None } } +impl<'p, T> PyDescrSetProtocolImpl for T where T: PyDescrProtocol<'p> {} impl PyDescrSetProtocolImpl for T where T: for<'p> PyDescrSetProtocol<'p>, @@ -121,42 +113,29 @@ where } trait PyDescrDelProtocolImpl { - fn __del__() -> Option; -} -impl<'p, T> PyDescrDelProtocolImpl for T -where - T: PyDescrProtocol<'p>, -{ - default fn __del__() -> Option { + fn __del__() -> Option { None } } +impl<'p, T> PyDescrDelProtocolImpl for T where T: PyDescrProtocol<'p> {} trait PyDescrSetNameProtocolImpl { - fn __set_name__() -> Option; -} -impl<'p, T> PyDescrSetNameProtocolImpl for T -where - T: PyDescrProtocol<'p>, -{ - default fn __set_name__() -> Option { + fn __set_name__() -> Option { None } } +impl<'p, T> PyDescrSetNameProtocolImpl for T where T: PyDescrProtocol<'p> {} #[doc(hidden)] pub trait PyDescrProtocolImpl { - fn methods() -> Vec; - fn tp_as_descr(type_object: &mut ffi::PyTypeObject); -} - -impl PyDescrProtocolImpl for T { - default fn methods() -> Vec { + fn methods() -> Vec { Vec::new() } - default fn tp_as_descr(_type_object: &mut ffi::PyTypeObject) {} + fn tp_as_descr(_type_object: &mut ffi::PyTypeObject) {} } +impl PyDescrProtocolImpl for T {} + impl<'p, T> PyDescrProtocolImpl for T where T: PyDescrProtocol<'p>, diff --git a/src/class/gc.rs b/src/class/gc.rs index 5470854e..22362c3a 100644 --- a/src/class/gc.rs +++ b/src/class/gc.rs @@ -29,12 +29,10 @@ pub trait PyGCClearProtocol<'p>: PyGCProtocol<'p> {} #[doc(hidden)] pub trait PyGCProtocolImpl { - fn update_type_object(type_object: &mut ffi::PyTypeObject); + fn update_type_object(_type_object: &mut ffi::PyTypeObject) {} } -impl<'p, T> PyGCProtocolImpl for T { - default fn update_type_object(_type_object: &mut ffi::PyTypeObject) {} -} +impl<'p, T> PyGCProtocolImpl for T {} impl<'p, T> PyGCProtocolImpl for T where @@ -71,19 +69,13 @@ impl<'p> PyVisit<'p> { } trait PyGCTraverseProtocolImpl { - fn tp_traverse() -> Option; -} - -impl<'p, T> PyGCTraverseProtocolImpl for T -where - T: PyGCProtocol<'p>, -{ - #[inline] - default fn tp_traverse() -> Option { + fn tp_traverse() -> Option { None } } +impl<'p, T> PyGCTraverseProtocolImpl for T where T: PyGCProtocol<'p> {} + #[doc(hidden)] impl PyGCTraverseProtocolImpl for T where @@ -119,19 +111,13 @@ where } trait PyGCClearProtocolImpl { - fn tp_clear() -> Option; -} - -impl<'p, T> PyGCClearProtocolImpl for T -where - T: PyGCProtocol<'p>, -{ - #[inline] - default fn tp_clear() -> Option { + fn tp_clear() -> Option { None } } +impl<'p, T> PyGCClearProtocolImpl for T where T: PyGCProtocol<'p> {} + impl PyGCClearProtocolImpl for T where T: for<'p> PyGCClearProtocol<'p>, diff --git a/src/class/iter.rs b/src/class/iter.rs index f014ab0a..780df61e 100644 --- a/src/class/iter.rs +++ b/src/class/iter.rs @@ -44,13 +44,10 @@ pub trait PyIterNextProtocol<'p>: PyIterProtocol<'p> { #[doc(hidden)] pub trait PyIterProtocolImpl { - fn tp_as_iter(typeob: &mut ffi::PyTypeObject); + fn tp_as_iter(_typeob: &mut ffi::PyTypeObject) {} } -impl PyIterProtocolImpl for T { - #[inline] - default fn tp_as_iter(_: &mut ffi::PyTypeObject) {} -} +impl PyIterProtocolImpl for T {} impl<'p, T> PyIterProtocolImpl for T where @@ -64,19 +61,13 @@ where } trait PyIterIterProtocolImpl { - fn tp_iter() -> Option; -} - -impl<'p, T> PyIterIterProtocolImpl for T -where - T: PyIterProtocol<'p>, -{ - #[inline] - default fn tp_iter() -> Option { + fn tp_iter() -> Option { None } } +impl<'p, T> PyIterIterProtocolImpl for T where T: PyIterProtocol<'p> {} + impl PyIterIterProtocolImpl for T where T: for<'p> PyIterIterProtocol<'p>, @@ -93,19 +84,13 @@ where } trait PyIterNextProtocolImpl { - fn tp_iternext() -> Option; -} - -impl<'p, T> PyIterNextProtocolImpl for T -where - T: PyIterProtocol<'p>, -{ - #[inline] - default fn tp_iternext() -> Option { + fn tp_iternext() -> Option { None } } +impl<'p, T> PyIterNextProtocolImpl for T where T: PyIterProtocol<'p> {} + impl PyIterNextProtocolImpl for T where T: for<'p> PyIterNextProtocol<'p>, diff --git a/src/class/macros.rs b/src/class/macros.rs index 6eddbddb..bcbb71f3 100644 --- a/src/class/macros.rs +++ b/src/class/macros.rs @@ -406,17 +406,16 @@ macro_rules! py_func_del { }}; } -#[macro_export] #[doc(hidden)] macro_rules! py_func_set_del { - ($trait:ident, $trait2:ident, $class:ident :: $f:ident/$f2:ident) => {{ - unsafe extern "C" fn wrap( + ($trait1:ident, $trait2:ident, $generic:ident, $fn_set:ident, $fn_del:ident) => {{ + unsafe extern "C" fn wrap<$generic>( slf: *mut $crate::ffi::PyObject, name: *mut $crate::ffi::PyObject, value: *mut $crate::ffi::PyObject, ) -> $crate::libc::c_int where - T: for<'p> $trait<'p> + for<'p> $trait2<'p>, + T: for<'p> $trait1<'p> + for<'p> $trait2<'p>, { use $crate::ObjectProtocol; @@ -425,33 +424,27 @@ macro_rules! py_func_set_del { let slf = py.mut_from_borrowed_ptr::(slf); let name = py.from_borrowed_ptr::<$crate::PyObjectRef>(name); + let result; if value.is_null() { - let result = match name.extract() { - Ok(name) => slf.$f2(name).into(), + result = match name.extract() { + Ok(name) => slf.$fn_del(name).into(), Err(e) => Err(e.into()), }; - match result { - Ok(_) => 0, - Err(e) => { - e.restore(py); - -1 - } - } } else { let value = py.from_borrowed_ptr::<$crate::PyObjectRef>(value); - let result = match name.extract() { + result = match name.extract() { Ok(name) => match value.extract() { - Ok(value) => slf.$f(name, value).into(), + Ok(value) => slf.$fn_set(name, value).into(), Err(e) => Err(e.into()), }, Err(e) => Err(e.into()), }; - match result { - Ok(_) => 0, - Err(e) => { - e.restore(py); - -1 - } + } + match result { + Ok(_) => 0, + Err(e) => { + e.restore(py); + -1 } } } diff --git a/src/class/mapping.rs b/src/class/mapping.rs index d94ced11..11141db7 100644 --- a/src/class/mapping.rs +++ b/src/class/mapping.rs @@ -106,21 +106,16 @@ pub trait PyMappingReversedProtocol<'p>: PyMappingProtocol<'p> { #[doc(hidden)] pub trait PyMappingProtocolImpl { - fn tp_as_mapping() -> Option; - fn methods() -> Vec; -} - -impl PyMappingProtocolImpl for T { - #[inline] - default fn tp_as_mapping() -> Option { + fn tp_as_mapping() -> Option { None } - #[inline] - default fn methods() -> Vec { + fn methods() -> Vec { Vec::new() } } +impl PyMappingProtocolImpl for T {} + impl<'p, T> PyMappingProtocolImpl for T where T: PyMappingProtocol<'p>, @@ -159,19 +154,13 @@ where } trait PyMappingLenProtocolImpl { - fn mp_length() -> Option; -} - -impl<'p, T> PyMappingLenProtocolImpl for T -where - T: PyMappingProtocol<'p>, -{ - #[inline] - default fn mp_length() -> Option { + fn mp_length() -> Option { None } } +impl<'p, T> PyMappingLenProtocolImpl for T where T: PyMappingProtocol<'p> {} + impl PyMappingLenProtocolImpl for T where T: for<'p> PyMappingLenProtocol<'p>, @@ -183,19 +172,13 @@ where } trait PyMappingGetItemProtocolImpl { - fn mp_subscript() -> Option; -} - -impl<'p, T> PyMappingGetItemProtocolImpl for T -where - T: PyMappingProtocol<'p>, -{ - #[inline] - default fn mp_subscript() -> Option { + fn mp_subscript() -> Option { None } } +impl<'p, T> PyMappingGetItemProtocolImpl for T where T: PyMappingProtocol<'p> {} + impl PyMappingGetItemProtocolImpl for T where T: for<'p> PyMappingGetItemProtocol<'p>, @@ -212,19 +195,13 @@ where } trait PyMappingSetItemProtocolImpl { - fn mp_ass_subscript() -> Option; -} - -impl<'p, T> PyMappingSetItemProtocolImpl for T -where - T: PyMappingProtocol<'p>, -{ - #[inline] - default fn mp_ass_subscript() -> Option { + fn mp_ass_subscript() -> Option { None } } +impl<'p, T> PyMappingSetItemProtocolImpl for T where T: PyMappingProtocol<'p> {} + impl PyMappingSetItemProtocolImpl for T where T: for<'p> PyMappingSetItemProtocol<'p>, @@ -236,19 +213,13 @@ where } trait PyMappingDelItemProtocolImpl { - fn mp_del_subscript() -> Option; -} - -impl<'p, T> PyMappingDelItemProtocolImpl for T -where - T: PyMappingProtocol<'p>, -{ - #[inline] - default fn mp_del_subscript() -> Option { + fn mp_del_subscript() -> Option { None } } +impl<'p, T> PyMappingDelItemProtocolImpl for T where T: PyMappingProtocol<'p> {} + impl PyMappingDelItemProtocolImpl for T where T: for<'p> PyMappingDelItemProtocol<'p>, @@ -268,52 +239,36 @@ where py_func_set_del!( PyMappingSetItemProtocol, PyMappingDelItemProtocol, - T::__setitem__ / __delitem__ + T, + __setitem__, + __delitem__ ) } } #[doc(hidden)] pub trait PyMappingContainsProtocolImpl { - fn __contains__() -> Option; -} - -impl<'p, T> PyMappingContainsProtocolImpl for T -where - T: PyMappingProtocol<'p>, -{ - #[inline] - default fn __contains__() -> Option { + fn __contains__() -> Option { None } } +impl<'p, T> PyMappingContainsProtocolImpl for T where T: PyMappingProtocol<'p> {} + #[doc(hidden)] pub trait PyMappingReversedProtocolImpl { - fn __reversed__() -> Option; -} - -impl<'p, T> PyMappingReversedProtocolImpl for T -where - T: PyMappingProtocol<'p>, -{ - #[inline] - default fn __reversed__() -> Option { + fn __reversed__() -> Option { None } } +impl<'p, T> PyMappingReversedProtocolImpl for T where T: PyMappingProtocol<'p> {} + #[doc(hidden)] pub trait PyMappingIterProtocolImpl { - fn __iter__() -> Option; -} - -impl<'p, T> PyMappingIterProtocolImpl for T -where - T: PyMappingProtocol<'p>, -{ - #[inline] - default fn __iter__() -> Option { + fn __iter__() -> Option { None } } + +impl<'p, T> PyMappingIterProtocolImpl for T where T: PyMappingProtocol<'p> {} diff --git a/src/class/methods.rs b/src/class/methods.rs index dad3ba5a..f3c0af89 100644 --- a/src/class/methods.rs +++ b/src/class/methods.rs @@ -124,22 +124,18 @@ impl PySetterDef { #[doc(hidden)] pub trait PyMethodsProtocolImpl { - fn py_methods() -> &'static [PyMethodDefType]; -} - -impl PyMethodsProtocolImpl for T { - default fn py_methods() -> &'static [PyMethodDefType] { + fn py_methods() -> &'static [PyMethodDefType] { NO_PY_METHODS } } +impl PyMethodsProtocolImpl for T {} + #[doc(hidden)] pub trait PyPropMethodsProtocolImpl { - fn py_methods() -> &'static [PyMethodDefType]; -} - -impl PyPropMethodsProtocolImpl for T { - default fn py_methods() -> &'static [PyMethodDefType] { + fn py_methods() -> &'static [PyMethodDefType] { NO_PY_METHODS } } + +impl PyPropMethodsProtocolImpl for T {} diff --git a/src/class/number.rs b/src/class/number.rs index 68df15c6..1d5168e0 100644 --- a/src/class/number.rs +++ b/src/class/number.rs @@ -326,48 +326,56 @@ pub trait PyNumberAddProtocol<'p>: PyNumberProtocol<'p> { type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberSubProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberMulProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberMatmulProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberTruedivProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberFloordivProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberModProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberDivmodProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberPowProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; @@ -375,30 +383,35 @@ pub trait PyNumberPowProtocol<'p>: PyNumberProtocol<'p> { type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberLShiftProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberRShiftProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberAndProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberXorProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberOrProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; @@ -411,67 +424,80 @@ pub trait PyNumberRAddProtocol<'p>: PyNumberProtocol<'p> { type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberRSubProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberRMulProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberRMatmulProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberRTruedivProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberRFloordivProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberRModProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberRDivmodProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberRPowProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Modulo: FromPyObject<'p>; type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberRLShiftProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberRRShiftProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberRAndProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberRXorProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberROrProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Success: IntoPyObject; @@ -482,55 +508,68 @@ pub trait PyNumberIAddProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Result: Into>; } + pub trait PyNumberISubProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Result: Into>; } + pub trait PyNumberIMulProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Result: Into>; } + pub trait PyNumberIMatmulProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Result: Into>; } + pub trait PyNumberITruedivProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Result: Into>; } + pub trait PyNumberIFloordivProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Result: Into>; } + pub trait PyNumberIModProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Result: Into>; } + pub trait PyNumberIDivmodProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Result: Into>; } + pub trait PyNumberIPowProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Modulo: FromPyObject<'p>; type Result: Into>; } + pub trait PyNumberILShiftProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Result: Into>; } + pub trait PyNumberIRShiftProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Result: Into>; } + pub trait PyNumberIAndProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Result: Into>; } + pub trait PyNumberIXorProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Result: Into>; } + pub trait PyNumberIOrProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Result: Into>; @@ -540,61 +579,61 @@ pub trait PyNumberNegProtocol<'p>: PyNumberProtocol<'p> { type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberPosProtocol<'p>: PyNumberProtocol<'p> { type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberAbsProtocol<'p>: PyNumberProtocol<'p> { type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberInvertProtocol<'p>: PyNumberProtocol<'p> { type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberComplexProtocol<'p>: PyNumberProtocol<'p> { type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberIntProtocol<'p>: PyNumberProtocol<'p> { type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberFloatProtocol<'p>: PyNumberProtocol<'p> { type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberRoundProtocol<'p>: PyNumberProtocol<'p> { type Success: IntoPyObject; type Result: Into>; } + pub trait PyNumberIndexProtocol<'p>: PyNumberProtocol<'p> { type Success: IntoPyObject; type Result: Into>; } #[doc(hidden)] -pub trait PyNumberProtocolImpl { - fn methods() -> Vec; - fn tp_as_number() -> Option; -} - -impl<'p, T> PyNumberProtocolImpl for T { - #[cfg(Py_3)] - default fn tp_as_number() -> Option { +pub trait PyNumberProtocolImpl: PyObjectProtocolImpl { + fn methods() -> Vec { + Vec::new() + } + fn tp_as_number() -> Option { if let Some(nb_bool) = ::nb_bool_fn() { + #[cfg(Py_3)] let meth = ffi::PyNumberMethods { nb_bool: Some(nb_bool), ..ffi::PyNumberMethods_INIT }; - Some(meth) - } else { - None - } - } - #[cfg(not(Py_3))] - default fn tp_as_number() -> Option { - if let Some(nb_bool) = ::nb_bool_fn() { + + #[cfg(not(Py_3))] let meth = ffi::PyNumberMethods { nb_nonzero: Some(nb_bool), ..ffi::PyNumberMethods_INIT @@ -604,11 +643,10 @@ impl<'p, T> PyNumberProtocolImpl for T { None } } - default fn methods() -> Vec { - Vec::new() - } } +impl<'p, T> PyNumberProtocolImpl for T {} + impl<'p, T> PyNumberProtocolImpl for T where T: PyNumberProtocol<'p>, @@ -757,16 +795,13 @@ where } trait PyNumberAddProtocolImpl { - fn nb_add() -> Option; -} -impl<'p, T> PyNumberAddProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_add() -> Option { + fn nb_add() -> Option { None } } + +impl<'p, T> PyNumberAddProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberAddProtocolImpl for T where T: for<'p> PyNumberAddProtocol<'p>, @@ -782,16 +817,13 @@ where } trait PyNumberSubProtocolImpl { - fn nb_subtract() -> Option; -} -impl<'p, T> PyNumberSubProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_subtract() -> Option { + fn nb_subtract() -> Option { None } } + +impl<'p, T> PyNumberSubProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberSubProtocolImpl for T where T: for<'p> PyNumberSubProtocol<'p>, @@ -807,16 +839,13 @@ where } trait PyNumberMulProtocolImpl { - fn nb_multiply() -> Option; -} -impl<'p, T> PyNumberMulProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_multiply() -> Option { + fn nb_multiply() -> Option { None } } + +impl<'p, T> PyNumberMulProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberMulProtocolImpl for T where T: for<'p> PyNumberMulProtocol<'p>, @@ -832,16 +861,13 @@ where } trait PyNumberMatmulProtocolImpl { - fn nb_matrix_multiply() -> Option; -} -impl<'p, T> PyNumberMatmulProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_matrix_multiply() -> Option { + fn nb_matrix_multiply() -> Option { None } } + +impl<'p, T> PyNumberMatmulProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberMatmulProtocolImpl for T where T: for<'p> PyNumberMatmulProtocol<'p>, @@ -857,16 +883,13 @@ where } trait PyNumberTruedivProtocolImpl { - fn nb_true_divide() -> Option; -} -impl<'p, T> PyNumberTruedivProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_true_divide() -> Option { + fn nb_true_divide() -> Option { None } } + +impl<'p, T> PyNumberTruedivProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberTruedivProtocolImpl for T where T: for<'p> PyNumberTruedivProtocol<'p>, @@ -882,16 +905,13 @@ where } trait PyNumberFloordivProtocolImpl { - fn nb_floor_divide() -> Option; -} -impl<'p, T> PyNumberFloordivProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_floor_divide() -> Option { + fn nb_floor_divide() -> Option { None } } + +impl<'p, T> PyNumberFloordivProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberFloordivProtocolImpl for T where T: for<'p> PyNumberFloordivProtocol<'p>, @@ -907,16 +927,13 @@ where } trait PyNumberModProtocolImpl { - fn nb_remainder() -> Option; -} -impl<'p, T> PyNumberModProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_remainder() -> Option { + fn nb_remainder() -> Option { None } } + +impl<'p, T> PyNumberModProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberModProtocolImpl for T where T: for<'p> PyNumberModProtocol<'p>, @@ -932,16 +949,13 @@ where } trait PyNumberDivmodProtocolImpl { - fn nb_divmod() -> Option; -} -impl<'p, T> PyNumberDivmodProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_divmod() -> Option { + fn nb_divmod() -> Option { None } } + +impl<'p, T> PyNumberDivmodProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberDivmodProtocolImpl for T where T: for<'p> PyNumberDivmodProtocol<'p>, @@ -957,16 +971,13 @@ where } trait PyNumberPowProtocolImpl { - fn nb_power() -> Option; -} -impl<'p, T> PyNumberPowProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_power() -> Option { + fn nb_power() -> Option { None } } + +impl<'p, T> PyNumberPowProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberPowProtocolImpl for T where T: for<'p> PyNumberPowProtocol<'p>, @@ -982,16 +993,13 @@ where } trait PyNumberLShiftProtocolImpl { - fn nb_lshift() -> Option; -} -impl<'p, T> PyNumberLShiftProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_lshift() -> Option { + fn nb_lshift() -> Option { None } } + +impl<'p, T> PyNumberLShiftProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberLShiftProtocolImpl for T where T: for<'p> PyNumberLShiftProtocol<'p>, @@ -1007,16 +1015,13 @@ where } trait PyNumberRShiftProtocolImpl { - fn nb_rshift() -> Option; -} -impl<'p, T> PyNumberRShiftProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_rshift() -> Option { + fn nb_rshift() -> Option { None } } + +impl<'p, T> PyNumberRShiftProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberRShiftProtocolImpl for T where T: for<'p> PyNumberRShiftProtocol<'p>, @@ -1032,16 +1037,13 @@ where } trait PyNumberAndProtocolImpl { - fn nb_and() -> Option; -} -impl<'p, T> PyNumberAndProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_and() -> Option { + fn nb_and() -> Option { None } } + +impl<'p, T> PyNumberAndProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberAndProtocolImpl for T where T: for<'p> PyNumberAndProtocol<'p>, @@ -1057,16 +1059,13 @@ where } trait PyNumberXorProtocolImpl { - fn nb_xor() -> Option; -} -impl<'p, T> PyNumberXorProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_xor() -> Option { + fn nb_xor() -> Option { None } } + +impl<'p, T> PyNumberXorProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberXorProtocolImpl for T where T: for<'p> PyNumberXorProtocol<'p>, @@ -1082,16 +1081,13 @@ where } trait PyNumberOrProtocolImpl { - fn nb_or() -> Option; -} -impl<'p, T> PyNumberOrProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_or() -> Option { + fn nb_or() -> Option { None } } + +impl<'p, T> PyNumberOrProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberOrProtocolImpl for T where T: for<'p> PyNumberOrProtocol<'p>, @@ -1107,16 +1103,13 @@ where } trait PyNumberIAddProtocolImpl { - fn nb_inplace_add() -> Option; -} -impl<'p, T> PyNumberIAddProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_inplace_add() -> Option { + fn nb_inplace_add() -> Option { None } } + +impl<'p, T> PyNumberIAddProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberIAddProtocolImpl for T where T: for<'p> PyNumberIAddProtocol<'p>, @@ -1127,16 +1120,13 @@ where } trait PyNumberISubProtocolImpl { - fn nb_inplace_subtract() -> Option; -} -impl<'p, T> PyNumberISubProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_inplace_subtract() -> Option { + fn nb_inplace_subtract() -> Option { None } } + +impl<'p, T> PyNumberISubProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberISubProtocolImpl for T where T: for<'p> PyNumberISubProtocol<'p>, @@ -1147,16 +1137,13 @@ where } trait PyNumberIMulProtocolImpl { - fn nb_inplace_multiply() -> Option; -} -impl<'p, T> PyNumberIMulProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_inplace_multiply() -> Option { + fn nb_inplace_multiply() -> Option { None } } + +impl<'p, T> PyNumberIMulProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberIMulProtocolImpl for T where T: for<'p> PyNumberIMulProtocol<'p>, @@ -1167,16 +1154,13 @@ where } trait PyNumberIMatmulProtocolImpl { - fn nb_inplace_matrix_multiply() -> Option; -} -impl<'p, T> PyNumberIMatmulProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_inplace_matrix_multiply() -> Option { + fn nb_inplace_matrix_multiply() -> Option { None } } + +impl<'p, T> PyNumberIMatmulProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberIMatmulProtocolImpl for T where T: for<'p> PyNumberIMatmulProtocol<'p>, @@ -1187,16 +1171,13 @@ where } trait PyNumberITruedivProtocolImpl { - fn nb_inplace_true_divide() -> Option; -} -impl<'p, T> PyNumberITruedivProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_inplace_true_divide() -> Option { + fn nb_inplace_true_divide() -> Option { None } } + +impl<'p, T> PyNumberITruedivProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberITruedivProtocolImpl for T where T: for<'p> PyNumberITruedivProtocol<'p>, @@ -1207,16 +1188,13 @@ where } trait PyNumberIFloordivProtocolImpl { - fn nb_inplace_floor_divide() -> Option; -} -impl<'p, T> PyNumberIFloordivProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_inplace_floor_divide() -> Option { + fn nb_inplace_floor_divide() -> Option { None } } + +impl<'p, T> PyNumberIFloordivProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberIFloordivProtocolImpl for T where T: for<'p> PyNumberIFloordivProtocol<'p>, @@ -1227,16 +1205,13 @@ where } trait PyNumberIModProtocolImpl { - fn nb_inplace_remainder() -> Option; -} -impl<'p, T> PyNumberIModProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_inplace_remainder() -> Option { + fn nb_inplace_remainder() -> Option { None } } + +impl<'p, T> PyNumberIModProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberIModProtocolImpl for T where T: for<'p> PyNumberIModProtocol<'p>, @@ -1247,16 +1222,13 @@ where } trait PyNumberIPowProtocolImpl { - fn nb_inplace_power() -> Option; -} -impl<'p, T> PyNumberIPowProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_inplace_power() -> Option { + fn nb_inplace_power() -> Option { None } } + +impl<'p, T> PyNumberIPowProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberIPowProtocolImpl for T where T: for<'p> PyNumberIPowProtocol<'p>, @@ -1267,16 +1239,13 @@ where } trait PyNumberILShiftProtocolImpl { - fn nb_inplace_lshift() -> Option; -} -impl<'p, T> PyNumberILShiftProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_inplace_lshift() -> Option { + fn nb_inplace_lshift() -> Option { None } } + +impl<'p, T> PyNumberILShiftProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberILShiftProtocolImpl for T where T: for<'p> PyNumberILShiftProtocol<'p>, @@ -1287,16 +1256,13 @@ where } trait PyNumberIRShiftProtocolImpl { - fn nb_inplace_rshift() -> Option; -} -impl<'p, T> PyNumberIRShiftProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_inplace_rshift() -> Option { + fn nb_inplace_rshift() -> Option { None } } + +impl<'p, T> PyNumberIRShiftProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberIRShiftProtocolImpl for T where T: for<'p> PyNumberIRShiftProtocol<'p>, @@ -1307,16 +1273,13 @@ where } trait PyNumberIAndProtocolImpl { - fn nb_inplace_and() -> Option; -} -impl<'p, T> PyNumberIAndProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_inplace_and() -> Option { + fn nb_inplace_and() -> Option { None } } + +impl<'p, T> PyNumberIAndProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberIAndProtocolImpl for T where T: for<'p> PyNumberIAndProtocol<'p>, @@ -1327,16 +1290,13 @@ where } trait PyNumberIXorProtocolImpl { - fn nb_inplace_xor() -> Option; -} -impl<'p, T> PyNumberIXorProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_inplace_xor() -> Option { + fn nb_inplace_xor() -> Option { None } } + +impl<'p, T> PyNumberIXorProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberIXorProtocolImpl for T where T: for<'p> PyNumberIXorProtocol<'p>, @@ -1347,16 +1307,13 @@ where } trait PyNumberIOrProtocolImpl { - fn nb_inplace_or() -> Option; -} -impl<'p, T> PyNumberIOrProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_inplace_or() -> Option { + fn nb_inplace_or() -> Option { None } } + +impl<'p, T> PyNumberIOrProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberIOrProtocolImpl for T where T: for<'p> PyNumberIOrProtocol<'p>, @@ -1367,184 +1324,125 @@ where } trait PyNumberRAddProtocolImpl { - fn __radd__() -> Option; -} -impl<'p, T> PyNumberRAddProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn __radd__() -> Option { + fn __radd__() -> Option { None } } +impl<'p, T> PyNumberRAddProtocolImpl for T where T: PyNumberProtocol<'p> {} + trait PyNumberRSubProtocolImpl { - fn __rsub__() -> Option; -} -impl<'p, T> PyNumberRSubProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn __rsub__() -> Option { + fn __rsub__() -> Option { None } } +impl<'p, T> PyNumberRSubProtocolImpl for T where T: PyNumberProtocol<'p> {} + trait PyNumberRMulProtocolImpl { - fn __rmul__() -> Option; -} -impl<'p, T> PyNumberRMulProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn __rmul__() -> Option { + fn __rmul__() -> Option { None } } +impl<'p, T> PyNumberRMulProtocolImpl for T where T: PyNumberProtocol<'p> {} + trait PyNumberRMatmulProtocolImpl { - fn __rmatmul__() -> Option; -} -impl<'p, T> PyNumberRMatmulProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn __rmatmul__() -> Option { + fn __rmatmul__() -> Option { None } } +impl<'p, T> PyNumberRMatmulProtocolImpl for T where T: PyNumberProtocol<'p> {} + trait PyNumberRTruedivProtocolImpl { - fn __rtruediv__() -> Option; -} -impl<'p, T> PyNumberRTruedivProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn __rtruediv__() -> Option { + fn __rtruediv__() -> Option { None } } +impl<'p, T> PyNumberRTruedivProtocolImpl for T where T: PyNumberProtocol<'p> {} + trait PyNumberRFloordivProtocolImpl { - fn __rfloordiv__() -> Option; -} -impl<'p, T> PyNumberRFloordivProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn __rfloordiv__() -> Option { + fn __rfloordiv__() -> Option { None } } +impl<'p, T> PyNumberRFloordivProtocolImpl for T where T: PyNumberProtocol<'p> {} + trait PyNumberRModProtocolImpl { - fn __rmod__() -> Option; -} -impl<'p, T> PyNumberRModProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn __rmod__() -> Option { + fn __rmod__() -> Option { None } } +impl<'p, T> PyNumberRModProtocolImpl for T where T: PyNumberProtocol<'p> {} + trait PyNumberRDivmodProtocolImpl { - fn __rdivmod__() -> Option; -} -impl<'p, T> PyNumberRDivmodProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn __rdivmod__() -> Option { + fn __rdivmod__() -> Option { None } } +impl<'p, T> PyNumberRDivmodProtocolImpl for T where T: PyNumberProtocol<'p> {} + trait PyNumberRPowProtocolImpl { - fn __rpow__() -> Option; -} -impl<'p, T> PyNumberRPowProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn __rpow__() -> Option { + fn __rpow__() -> Option { None } } +impl<'p, T> PyNumberRPowProtocolImpl for T where T: PyNumberProtocol<'p> {} + trait PyNumberRLShiftProtocolImpl { - fn __rlshift__() -> Option; -} -impl<'p, T> PyNumberRLShiftProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn __rlshift__() -> Option { + fn __rlshift__() -> Option { None } } +impl<'p, T> PyNumberRLShiftProtocolImpl for T where T: PyNumberProtocol<'p> {} + trait PyNumberRRShiftProtocolImpl { - fn __rrshift__() -> Option; -} -impl<'p, T> PyNumberRRShiftProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn __rrshift__() -> Option { + fn __rrshift__() -> Option { None } } +impl<'p, T> PyNumberRRShiftProtocolImpl for T where T: PyNumberProtocol<'p> {} + trait PyNumberRAndProtocolImpl { - fn __rand__() -> Option; -} -impl<'p, T> PyNumberRAndProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn __rand__() -> Option { + fn __rand__() -> Option { None } } +impl<'p, T> PyNumberRAndProtocolImpl for T where T: PyNumberProtocol<'p> {} + trait PyNumberRXorProtocolImpl { - fn __rxor__() -> Option; -} -impl<'p, T> PyNumberRXorProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn __rxor__() -> Option { + fn __rxor__() -> Option { None } } +impl<'p, T> PyNumberRXorProtocolImpl for T where T: PyNumberProtocol<'p> {} + trait PyNumberROrProtocolImpl { - fn __ror__() -> Option; -} -impl<'p, T> PyNumberROrProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn __ror__() -> Option { + fn __ror__() -> Option { None } } +impl<'p, T> PyNumberROrProtocolImpl for T where T: PyNumberProtocol<'p> {} + trait PyNumberNegProtocolImpl { - fn nb_negative() -> Option; -} -impl<'p, T> PyNumberNegProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_negative() -> Option { + fn nb_negative() -> Option { None } } + +impl<'p, T> PyNumberNegProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberNegProtocolImpl for T where T: for<'p> PyNumberNegProtocol<'p>, @@ -1561,16 +1459,13 @@ where } trait PyNumberPosProtocolImpl { - fn nb_positive() -> Option; -} -impl<'p, T> PyNumberPosProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_positive() -> Option { + fn nb_positive() -> Option { None } } + +impl<'p, T> PyNumberPosProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberPosProtocolImpl for T where T: for<'p> PyNumberPosProtocol<'p>, @@ -1586,16 +1481,13 @@ where } trait PyNumberAbsProtocolImpl { - fn nb_absolute() -> Option; -} -impl<'p, T> PyNumberAbsProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_absolute() -> Option { + fn nb_absolute() -> Option { None } } + +impl<'p, T> PyNumberAbsProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberAbsProtocolImpl for T where T: for<'p> PyNumberAbsProtocol<'p>, @@ -1611,16 +1503,13 @@ where } trait PyNumberInvertProtocolImpl { - fn nb_invert() -> Option; -} -impl<'p, T> PyNumberInvertProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_invert() -> Option { + fn nb_invert() -> Option { None } } + +impl<'p, T> PyNumberInvertProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberInvertProtocolImpl for T where T: for<'p> PyNumberInvertProtocol<'p>, @@ -1636,16 +1525,13 @@ where } trait PyNumberIntProtocolImpl { - fn nb_int() -> Option; -} -impl<'p, T> PyNumberIntProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_int() -> Option { + fn nb_int() -> Option { None } } + +impl<'p, T> PyNumberIntProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberIntProtocolImpl for T where T: for<'p> PyNumberIntProtocol<'p>, @@ -1661,16 +1547,13 @@ where } trait PyNumberFloatProtocolImpl { - fn nb_float() -> Option; -} -impl<'p, T> PyNumberFloatProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_float() -> Option { + fn nb_float() -> Option { None } } + +impl<'p, T> PyNumberFloatProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberFloatProtocolImpl for T where T: for<'p> PyNumberFloatProtocol<'p>, @@ -1686,16 +1569,13 @@ where } trait PyNumberIndexProtocolImpl { - fn nb_index() -> Option; -} -impl<'p, T> PyNumberIndexProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn nb_index() -> Option { + fn nb_index() -> Option { None } } + +impl<'p, T> PyNumberIndexProtocolImpl for T where T: PyNumberProtocol<'p> {} + impl PyNumberIndexProtocolImpl for T where T: for<'p> PyNumberIndexProtocol<'p>, @@ -1711,25 +1591,17 @@ where } trait PyNumberComplexProtocolImpl { - fn __complex__() -> Option; -} -impl<'p, T> PyNumberComplexProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn __complex__() -> Option { + fn __complex__() -> Option { None } } +impl<'p, T> PyNumberComplexProtocolImpl for T where T: PyNumberProtocol<'p> {} + trait PyNumberRoundProtocolImpl { - fn __round__() -> Option; -} -impl<'p, T> PyNumberRoundProtocolImpl for T -where - T: PyNumberProtocol<'p>, -{ - default fn __round__() -> Option { + fn __round__() -> Option { None } } + +impl<'p, T> PyNumberRoundProtocolImpl for T where T: PyNumberProtocol<'p> {} diff --git a/src/class/sequence.rs b/src/class/sequence.rs index 92fdd106..81164772 100644 --- a/src/class/sequence.rs +++ b/src/class/sequence.rs @@ -3,8 +3,6 @@ //! Python Sequence Interface //! Trait and support implementation for implementing sequence -use std::os::raw::c_int; - use callback::{BoolCallbackConverter, LenResultConverter, PyObjectCallbackConverter}; use conversion::{FromPyObject, IntoPyObject}; use err::{PyErr, PyResult}; @@ -12,6 +10,7 @@ use ffi; use objectprotocol::ObjectProtocol; use objects::{exc, PyObjectRef}; use python::Python; +use std::os::raw::c_int; use typeob::PyTypeInfo; /// Sequece interface @@ -129,22 +128,17 @@ pub trait PySequenceInplaceRepeatProtocol<'p>: PySequenceProtocol<'p> + IntoPyOb #[doc(hidden)] pub trait PySequenceProtocolImpl { - fn tp_as_sequence() -> Option; -} - -impl PySequenceProtocolImpl for T { - #[inline] - default fn tp_as_sequence() -> Option { + fn tp_as_sequence() -> Option { None } } +impl PySequenceProtocolImpl for T {} + impl<'p, T> PySequenceProtocolImpl for T where T: PySequenceProtocol<'p>, { - #[cfg(Py_3)] - #[inline] fn tp_as_sequence() -> Option { let f = if let Some(df) = Self::sq_del_item() { Some(df) @@ -152,7 +146,8 @@ where Self::sq_ass_item() }; - Some(ffi::PySequenceMethods { + #[cfg(Py_3)] + return Some(ffi::PySequenceMethods { sq_length: Self::sq_length(), sq_concat: Self::sq_concat(), sq_repeat: Self::sq_repeat(), @@ -163,18 +158,10 @@ where sq_contains: Self::sq_contains(), sq_inplace_concat: Self::sq_inplace_concat(), sq_inplace_repeat: Self::sq_inplace_repeat(), - }) - } - #[cfg(not(Py_3))] - #[inline] - fn tp_as_sequence() -> Option { - let f = if let Some(df) = Self::sq_del_item() { - Some(df) - } else { - Self::sq_ass_item() - }; + }); - Some(ffi::PySequenceMethods { + #[cfg(not(Py_3))] + return Some(ffi::PySequenceMethods { sq_length: Self::sq_length(), sq_concat: Self::sq_concat(), sq_repeat: Self::sq_repeat(), @@ -185,53 +172,39 @@ where sq_contains: Self::sq_contains(), sq_inplace_concat: Self::sq_inplace_concat(), sq_inplace_repeat: Self::sq_inplace_repeat(), - }) + }); } } trait PySequenceLenProtocolImpl { - fn sq_length() -> Option; -} - -impl<'p, T> PySequenceLenProtocolImpl for T -where - T: PySequenceProtocol<'p>, -{ - #[inline] - default fn sq_length() -> Option { + fn sq_length() -> Option { None } } +impl<'p, T> PySequenceLenProtocolImpl for T where T: PySequenceProtocol<'p> {} + impl PySequenceLenProtocolImpl for T where T: for<'p> PySequenceLenProtocol<'p>, { - #[inline] fn sq_length() -> Option { py_len_func!(PySequenceLenProtocol, T::__len__, LenResultConverter) } } trait PySequenceGetItemProtocolImpl { - fn sq_item() -> Option; -} - -impl<'p, T> PySequenceGetItemProtocolImpl for T -where - T: PySequenceProtocol<'p>, -{ - #[inline] - default fn sq_item() -> Option { + fn sq_item() -> Option { None } } +impl<'p, T> PySequenceGetItemProtocolImpl for T where T: PySequenceProtocol<'p> {} + impl PySequenceGetItemProtocolImpl for T where T: for<'p> PySequenceGetItemProtocol<'p>, { - #[inline] fn sq_item() -> Option { py_ssizearg_func!( PySequenceGetItemProtocol, @@ -243,24 +216,17 @@ where } trait PySequenceSetItemProtocolImpl { - fn sq_ass_item() -> Option; -} - -impl<'p, T> PySequenceSetItemProtocolImpl for T -where - T: PySequenceProtocol<'p>, -{ - #[inline] - default fn sq_ass_item() -> Option { + fn sq_ass_item() -> Option { None } } +impl<'p, T> PySequenceSetItemProtocolImpl for T where T: PySequenceProtocol<'p> {} + impl PySequenceSetItemProtocolImpl for T where T: for<'p> PySequenceSetItemProtocol<'p>, { - #[inline] fn sq_ass_item() -> Option { unsafe extern "C" fn wrap( slf: *mut ffi::PyObject, @@ -301,23 +267,17 @@ where } trait PySequenceDelItemProtocolImpl { - fn sq_del_item() -> Option; -} -impl<'p, T> PySequenceDelItemProtocolImpl for T -where - T: PySequenceProtocol<'p>, -{ - #[inline] - default fn sq_del_item() -> Option { + fn sq_del_item() -> Option { None } } +impl<'p, T> PySequenceDelItemProtocolImpl for T where T: PySequenceProtocol<'p> {} + impl PySequenceDelItemProtocolImpl for T where T: for<'p> PySequenceDelItemProtocol<'p>, { - #[inline] default fn sq_del_item() -> Option { unsafe extern "C" fn wrap( slf: *mut ffi::PyObject, @@ -357,7 +317,6 @@ impl PySequenceDelItemProtocolImpl for T where T: for<'p> PySequenceSetItemProtocol<'p> + for<'p> PySequenceDelItemProtocol<'p>, { - #[inline] fn sq_del_item() -> Option { unsafe extern "C" fn wrap( slf: *mut ffi::PyObject, @@ -400,24 +359,17 @@ where } trait PySequenceContainsProtocolImpl { - fn sq_contains() -> Option; -} - -impl<'p, T> PySequenceContainsProtocolImpl for T -where - T: PySequenceProtocol<'p>, -{ - #[inline] - default fn sq_contains() -> Option { + fn sq_contains() -> Option { None } } +impl<'p, T> PySequenceContainsProtocolImpl for T where T: PySequenceProtocol<'p> {} + impl PySequenceContainsProtocolImpl for T where T: for<'p> PySequenceContainsProtocol<'p>, { - #[inline] fn sq_contains() -> Option { py_binary_func!( PySequenceContainsProtocol, @@ -430,24 +382,17 @@ where } trait PySequenceConcatProtocolImpl { - fn sq_concat() -> Option; -} - -impl<'p, T> PySequenceConcatProtocolImpl for T -where - T: PySequenceProtocol<'p>, -{ - #[inline] - default fn sq_concat() -> Option { + fn sq_concat() -> Option { None } } +impl<'p, T> PySequenceConcatProtocolImpl for T where T: PySequenceProtocol<'p> {} + impl PySequenceConcatProtocolImpl for T where T: for<'p> PySequenceConcatProtocol<'p>, { - #[inline] fn sq_concat() -> Option { py_binary_func!( PySequenceConcatProtocol, @@ -459,24 +404,17 @@ where } trait PySequenceRepeatProtocolImpl { - fn sq_repeat() -> Option; -} - -impl<'p, T> PySequenceRepeatProtocolImpl for T -where - T: PySequenceProtocol<'p>, -{ - #[inline] - default fn sq_repeat() -> Option { + fn sq_repeat() -> Option { None } } +impl<'p, T> PySequenceRepeatProtocolImpl for T where T: PySequenceProtocol<'p> {} + impl PySequenceRepeatProtocolImpl for T where T: for<'p> PySequenceRepeatProtocol<'p>, { - #[inline] fn sq_repeat() -> Option { py_ssizearg_func!( PySequenceRepeatProtocol, @@ -488,24 +426,17 @@ where } trait PySequenceInplaceConcatProtocolImpl { - fn sq_inplace_concat() -> Option; -} - -impl<'p, T> PySequenceInplaceConcatProtocolImpl for T -where - T: PySequenceProtocol<'p>, -{ - #[inline] - default fn sq_inplace_concat() -> Option { + fn sq_inplace_concat() -> Option { None } } +impl<'p, T> PySequenceInplaceConcatProtocolImpl for T where T: PySequenceProtocol<'p> {} + impl PySequenceInplaceConcatProtocolImpl for T where T: for<'p> PySequenceInplaceConcatProtocol<'p>, { - #[inline] fn sq_inplace_concat() -> Option { py_binary_func!( PySequenceInplaceConcatProtocol, @@ -517,24 +448,17 @@ where } trait PySequenceInplaceRepeatProtocolImpl { - fn sq_inplace_repeat() -> Option; -} - -impl<'p, T> PySequenceInplaceRepeatProtocolImpl for T -where - T: PySequenceProtocol<'p>, -{ - #[inline] - default fn sq_inplace_repeat() -> Option { + fn sq_inplace_repeat() -> Option { None } } +impl<'p, T> PySequenceInplaceRepeatProtocolImpl for T where T: PySequenceProtocol<'p> {} + impl PySequenceInplaceRepeatProtocolImpl for T where T: for<'p> PySequenceInplaceRepeatProtocol<'p>, { - #[inline] fn sq_inplace_repeat() -> Option { py_ssizearg_func!( PySequenceInplaceRepeatProtocol, diff --git a/src/conversion.rs b/src/conversion.rs index f87a4384..a1f082a2 100644 --- a/src/conversion.rs +++ b/src/conversion.rs @@ -23,16 +23,6 @@ pub trait ToBorrowedObject: ToPyObject { /// May be more efficient than `to_object` because it does not need /// to touch any reference counts when the input object already is a Python object. fn with_borrowed_ptr(&self, py: Python, f: F) -> R - where - F: FnOnce(*mut ffi::PyObject) -> R; -} - -impl ToBorrowedObject for T -where - T: ToPyObject, -{ - #[inline] - default fn with_borrowed_ptr(&self, py: Python, f: F) -> R where F: FnOnce(*mut ffi::PyObject) -> R, { @@ -43,6 +33,8 @@ where } } +impl ToBorrowedObject for T where T: ToPyObject {} + /// Conversion trait that allows various objects to be converted into `PyObject` /// by consuming original object. pub trait IntoPyObject { diff --git a/src/freelist.rs b/src/freelist.rs index 15c98e2b..722a7723 100644 --- a/src/freelist.rs +++ b/src/freelist.rs @@ -1,11 +1,11 @@ // Copyright (c) 2017-present PyO3 Project and Contributors //! Free allocation list -use std; use err::PyResult; use ffi; use python::Python; +use std::mem; use std::os::raw::c_void; use typeob::{PyObjectAlloc, PyTypeInfo}; @@ -45,7 +45,7 @@ impl FreeList { if idx == 0 { None } else { - match std::mem::replace(&mut self.entries[idx - 1], Slot::Empty) { + match mem::replace(&mut self.entries[idx - 1], Slot::Empty) { Slot::Filled(v) => { self.split = idx - 1; Some(v) diff --git a/src/lib.rs b/src/lib.rs index 8835e2e7..20d02832 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -148,7 +148,7 @@ pub use noargs::NoArgs; pub use object::PyObject; pub use objectprotocol::ObjectProtocol; pub use objects::*; -pub use python::{IntoPyDictPointer, IntoPyPointer, Python, ToPyPointer}; +pub use python::{IntoPyPointer, Python, ToPyPointer}; pub use pythonrun::{init_once, prepare_freethreaded_python, GILGuard, GILPool}; pub use typeob::{PyObjectAlloc, PyRawObject, PyTypeInfo}; pub mod class; diff --git a/src/noargs.rs b/src/noargs.rs index 4634254b..8ce5af8a 100644 --- a/src/noargs.rs +++ b/src/noargs.rs @@ -1,23 +1,22 @@ // Copyright (c) 2017-present PyO3 Project and Contributors -use std; - use conversion::{IntoPyObject, IntoPyTuple, ToPyObject}; -use ffi; use instance::Py; use object::PyObject; use objects::PyTuple; -use python::{IntoPyDictPointer, Python}; +use python::Python; /// An empty struct that represents the empty argument list. /// Corresponds to the empty tuple `()` in Python. /// /// # Example /// ``` -/// let gil = pyo3::Python::acquire_gil(); +/// # use pyo3::prelude::*; +/// +/// let gil = Python::acquire_gil(); /// let py = gil.python(); /// let os = py.import("os").unwrap(); -/// let pid = os.call("get_pid", pyo3::NoArgs, pyo3::NoArgs); +/// let pid = os.call("get_pid", NoArgs, None); /// ``` #[derive(Copy, Clone, Debug)] pub struct NoArgs; @@ -49,10 +48,3 @@ impl IntoPyObject for NoArgs { PyTuple::empty(py).into() } } - -/// Converts `NoArgs` to an null pointer. -impl IntoPyDictPointer for NoArgs { - fn into_dict_ptr(self, _: Python) -> *mut ffi::PyObject { - std::ptr::null_mut() - } -} diff --git a/src/object.rs b/src/object.rs index 61298037..ec4992bf 100644 --- a/src/object.rs +++ b/src/object.rs @@ -8,8 +8,9 @@ use conversion::{ use err::{PyDowncastError, PyErr, PyResult}; use ffi; use instance::{AsPyRef, PyObjectWithToken}; +use objects::PyDict; use objects::{PyObjectRef, PyTuple}; -use python::{IntoPyDictPointer, IntoPyPointer, Python, ToPyPointer}; +use python::{IntoPyPointer, Python, ToPyPointer}; use pythonrun; /// Safe wrapper around unsafe `*mut ffi::PyObject` pointer. @@ -166,18 +167,19 @@ impl PyObject { /// Calls the object. /// This is equivalent to the Python expression: 'self(*args, **kwargs)' - pub fn call(&self, py: Python, args: A, kwargs: K) -> PyResult + pub fn call(&self, py: Python, args: A, kwargs: Option) -> PyResult where A: IntoPyTuple, - K: IntoPyDictPointer, { let args = args.into_tuple(py).into_ptr(); - let kwargs = kwargs.into_dict_ptr(py); let result = unsafe { - PyObject::from_owned_ptr_or_err(py, ffi::PyObject_Call(self.as_ptr(), args, kwargs)) + PyObject::from_owned_ptr_or_err( + py, + ffi::PyObject_Call(self.as_ptr(), args, kwargs.into_ptr()), + ) }; py.xdecref(args); - py.xdecref(kwargs); + py.xdecref(kwargs.into_ptr()); result } @@ -219,15 +221,14 @@ impl PyObject { py: Python, name: &str, args: A, - kwargs: K, + kwargs: PyDict, ) -> PyResult where A: IntoPyTuple, - K: IntoPyDictPointer, { name.with_borrowed_ptr(py, |name| unsafe { let args = args.into_tuple(py).into_ptr(); - let kwargs = kwargs.into_dict_ptr(py); + let kwargs = kwargs.into_ptr(); let ptr = ffi::PyObject_GetAttr(self.as_ptr(), name); let result = PyObject::from_owned_ptr_or_err(py, ffi::PyObject_Call(ptr, args, kwargs)); ffi::Py_DECREF(ptr); diff --git a/src/objectprotocol.rs b/src/objectprotocol.rs index 0d01d779..349e0de4 100644 --- a/src/objectprotocol.rs +++ b/src/objectprotocol.rs @@ -1,16 +1,16 @@ // Copyright (c) 2017-present PyO3 Project and Contributors -use std; -use std::cmp::Ordering; -use std::os::raw::c_int; - use conversion::{FromPyObject, IntoPyTuple, PyTryFrom, ToBorrowedObject, ToPyObject}; use err::{self, PyDowncastError, PyErr, PyResult}; use ffi; use instance::PyObjectWithToken; use object::PyObject; +use objects::PyDict; use objects::{PyIterator, PyObjectRef, PyString, PyTuple, PyType}; -use python::{IntoPyDictPointer, IntoPyPointer, Python, ToPyPointer}; +use python::{IntoPyPointer, Python, ToPyPointer}; +use std; +use std::cmp::Ordering; +use std::os::raw::c_int; use typeob::PyTypeInfo; /// Python object model helper methods @@ -85,10 +85,9 @@ pub trait ObjectProtocol { /// Calls the object. /// This is equivalent to the Python expression: `self(*args, **kwargs)` - fn call(&self, args: A, kwargs: K) -> PyResult<&PyObjectRef> + fn call(&self, args: A, kwargs: Option) -> PyResult<&PyObjectRef> where - A: IntoPyTuple, - K: IntoPyDictPointer; + A: IntoPyTuple; /// Calls the object. /// This is equivalent to the Python expression: `self()` @@ -108,12 +107,11 @@ pub trait ObjectProtocol { /// let obj = SomePyObject::new(); /// let args = (arg1, arg2, arg3); /// let kwargs = ((key1, value1), (key2, value2)); - /// let pid = obj.call_method("do_something", args, kwargs); + /// let pid = obj.call_method("do_something", args, kwargs.into_py_dict()); /// ``` - fn call_method(&self, name: &str, args: A, kwargs: K) -> PyResult<&PyObjectRef> + fn call_method(&self, name: &str, args: A, kwargs: Option) -> PyResult<&PyObjectRef> where - A: IntoPyTuple, - K: IntoPyDictPointer; + A: IntoPyTuple; /// Calls a method on the object. /// This is equivalent to the Python expression: `self.name()` @@ -313,19 +311,17 @@ where unsafe { ffi::PyCallable_Check(self.as_ptr()) != 0 } } - fn call(&self, args: A, kwargs: K) -> PyResult<&PyObjectRef> + fn call(&self, args: A, kwargs: Option) -> PyResult<&PyObjectRef> where A: IntoPyTuple, - K: IntoPyDictPointer, { let args = args.into_tuple(self.py()).into_ptr(); - let kw_ptr = kwargs.into_dict_ptr(self.py()); let result = unsafe { - self.py() - .from_owned_ptr_or_err(ffi::PyObject_Call(self.as_ptr(), args, kw_ptr)) + let return_value = ffi::PyObject_Call(self.as_ptr(), args, kwargs.into_ptr()); + self.py().from_owned_ptr_or_err(return_value) }; self.py().xdecref(args); - self.py().xdecref(kw_ptr); + self.py().xdecref(kwargs.into_ptr()); result } @@ -358,10 +354,9 @@ where result } - fn call_method(&self, name: &str, args: A, kwargs: K) -> PyResult<&PyObjectRef> + fn call_method(&self, name: &str, args: A, kwargs: Option) -> PyResult<&PyObjectRef> where A: IntoPyTuple, - K: IntoPyDictPointer, { name.with_borrowed_ptr(self.py(), |name| unsafe { let ptr = ffi::PyObject_GetAttr(self.as_ptr(), name); @@ -369,13 +364,12 @@ where return Err(PyErr::fetch(self.py())); } let args = args.into_tuple(self.py()).into_ptr(); - let kw_ptr = kwargs.into_dict_ptr(self.py()); - let result = self - .py() - .from_owned_ptr_or_err(ffi::PyObject_Call(ptr, args, kw_ptr)); + let kwargs = kwargs.into_ptr(); + let result_ptr = ffi::PyObject_Call(ptr, args, kwargs); + let result = self.py().from_owned_ptr_or_err(result_ptr); ffi::Py_DECREF(ptr); self.py().xdecref(args); - self.py().xdecref(kw_ptr); + self.py().xdecref(kwargs); result }) } @@ -531,7 +525,6 @@ mod test { use super::*; use conversion::{PyTryFrom, ToPyObject}; use instance::AsPyRef; - use noargs::NoArgs; use objects::PyString; use python::Python; @@ -559,7 +552,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,), NoArgs).is_err()); + assert!(a.call_method("nonexistent_method", (1,), None).is_err()); assert!(a.call_method0("nonexistent_method").is_err()); assert!(a.call_method1("nonexistent_method", (1,)).is_err()); } diff --git a/src/objects/bytearray.rs b/src/objects/bytearray.rs index bb55ccd8..c10940e4 100644 --- a/src/objects/bytearray.rs +++ b/src/objects/bytearray.rs @@ -5,8 +5,8 @@ use ffi; use instance::PyObjectWithToken; use object::PyObject; use python::{Python, ToPyPointer}; -use std; use std::os::raw::c_char; +use std::slice; /// Represents a Python `bytearray`. #[repr(transparent)] @@ -51,7 +51,7 @@ impl PyByteArray { unsafe { let buffer = ffi::PyByteArray_AsString(self.0.as_ptr()) as *mut u8; let length = ffi::PyByteArray_Size(self.0.as_ptr()) as usize; - std::slice::from_raw_parts_mut(buffer, length) + slice::from_raw_parts_mut(buffer, length) } } diff --git a/src/objects/dict.rs b/src/objects/dict.rs index 83198405..8c1b88f0 100644 --- a/src/objects/dict.rs +++ b/src/objects/dict.rs @@ -1,15 +1,14 @@ // Copyright (c) 2017-present PyO3 Project and Contributors -use std; -use std::{cmp, collections, hash, mem}; - use conversion::{IntoPyObject, ToBorrowedObject, ToPyObject}; use err::{self, PyErr, PyResult}; use ffi; -use instance::{Py, PyObjectWithToken}; +use instance::PyObjectWithToken; use object::PyObject; use objects::{PyList, PyObjectRef}; -use python::{IntoPyDictPointer, IntoPyPointer, Python, ToPyPointer}; +use python::{Python, ToPyPointer}; +use std; +use std::{cmp, collections, hash, mem}; /// Represents a Python `dict`. #[repr(transparent)] @@ -19,8 +18,6 @@ pyobject_native_type!(PyDict, ffi::PyDict_Type, ffi::PyDict_Check); impl PyDict { /// Creates a new empty dictionary. - /// - /// May panic when running out of memory. pub fn new(py: Python) -> &PyDict { unsafe { py.from_owned_ptr::(ffi::PyDict_New()) } } @@ -169,20 +166,6 @@ impl<'a> std::iter::IntoIterator for &'a PyDict { } } -impl<'a> IntoPyDictPointer for &'a PyDict { - #[must_use] - fn into_dict_ptr(self, _py: Python) -> *mut ffi::PyObject { - self.into_ptr() - } -} - -impl IntoPyDictPointer for Py { - #[must_use] - fn into_dict_ptr(self, _py: Python) -> *mut ffi::PyObject { - self.into_ptr() - } -} - impl ToPyObject for collections::HashMap where K: hash::Hash + cmp::Eq + ToPyObject, @@ -245,19 +228,27 @@ where } } -impl IntoPyDictPointer for I +/// Conversion trait that allows a sequence of tuples to be converted into `PyDict` +/// Primary use case for this trait is `call` and `call_method` methods as keywords argument. +pub trait IntoPyDict { + /// Converts self into a `PyDict` object pointer. Whether pointer owned or borrowed + /// depends on implementation. + fn into_py_dict(self, py: Python) -> &PyDict; +} + +impl IntoPyDict for I where K: ToPyObject, V: ToPyObject, I: IntoIterator, { - default fn into_dict_ptr(self, py: Python) -> *mut ffi::PyObject { + fn into_py_dict(self, py: Python) -> &PyDict { let dict = PyDict::new(py); for (key, value) in self { dict.set_item(key, value) .expect("Failed to set_item on dict"); } - dict.into_ptr() + dict } } @@ -265,10 +256,11 @@ where mod test { use conversion::{IntoPyObject, PyTryFrom, ToPyObject}; use instance::AsPyRef; + use objects::dict::IntoPyDict; use objects::{PyDict, PyTuple}; - use python::{IntoPyDictPointer, Python}; + use python::Python; use std::collections::{BTreeMap, HashMap}; - use {ObjectProtocol, PyObject}; + use ObjectProtocol; #[test] fn test_new() { @@ -558,12 +550,10 @@ mod test { let mut map = HashMap::::new(); map.insert(1, 1); - let m = map.into_dict_ptr(py); - let ob = unsafe { PyObject::from_owned_ptr(py, m) }; - let py_map = ::try_from(ob.as_ref(py)).unwrap(); + let py_map = map.into_py_dict(py); - assert!(py_map.len() == 1); - assert!(py_map.get_item(1).unwrap().extract::().unwrap() == 1); + assert_eq!(py_map.len(), 1); + assert_eq!(py_map.get_item(1).unwrap().extract::().unwrap(), 1); } #[test] @@ -589,12 +579,10 @@ mod test { let mut map = BTreeMap::::new(); map.insert(1, 1); - let m = map.into_dict_ptr(py); - let ob = unsafe { PyObject::from_owned_ptr(py, m) }; - let py_map = ::try_from(ob.as_ref(py)).unwrap(); + let py_map = map.into_py_dict(py); - assert!(py_map.len() == 1); - assert!(py_map.get_item(1).unwrap().extract::().unwrap() == 1); + assert_eq!(py_map.len(), 1); + assert_eq!(py_map.get_item(1).unwrap().extract::().unwrap(), 1); } #[test] @@ -602,12 +590,10 @@ mod test { let gil = Python::acquire_gil(); let py = gil.python(); - let map = vec![("a", 1), ("b", 2), ("c", 3)]; - let m = map.into_dict_ptr(py); - let ob = unsafe { PyObject::from_owned_ptr(py, m) }; - let py_map = ::try_from(ob.as_ref(py)).unwrap(); + let vec = vec![("a", 1), ("b", 2), ("c", 3)]; + let py_map = vec.into_py_dict(py); - assert!(py_map.len() == 3); - assert!(py_map.get_item("b").unwrap().extract::().unwrap() == 2); + assert_eq!(py_map.len(), 3); + assert_eq!(py_map.get_item("b").unwrap().extract::().unwrap(), 2); } } diff --git a/src/objects/mod.rs b/src/objects/mod.rs index 5d0ba276..6cacfbc6 100644 --- a/src/objects/mod.rs +++ b/src/objects/mod.rs @@ -5,6 +5,7 @@ pub use self::bytearray::PyByteArray; pub use self::datetime::PyDeltaAccess; pub use self::datetime::{PyDate, PyDateTime, PyDelta, PyTime, PyTzInfo}; pub use self::datetime::{PyDateAccess, PyTimeAccess}; +pub use self::dict::IntoPyDict; pub use self::dict::PyDict; pub use self::floatob::PyFloat; pub use self::iterator::PyIterator; diff --git a/src/objects/module.rs b/src/objects/module.rs index 33e7d36d..eeb597e1 100644 --- a/src/objects/module.rs +++ b/src/objects/module.rs @@ -2,7 +2,6 @@ // // based on Daniel Grunwald's https://github.com/dgrunwald/rust-cpython -use std; use std::ffi::{CStr, CString}; use std::os::raw::c_char; @@ -13,7 +12,8 @@ use instance::PyObjectWithToken; use object::PyObject; use objectprotocol::ObjectProtocol; use objects::{exc, PyDict, PyObjectRef, PyType}; -use python::{IntoPyDictPointer, Python, ToPyPointer}; +use python::{Python, ToPyPointer}; +use std::str; use typeob::{initialize_type, PyTypeInfo}; /// Represents a Python `module` object. @@ -80,7 +80,7 @@ impl PyModule { Err(PyErr::fetch(self.py())) } else { let slice = CStr::from_ptr(ptr).to_bytes(); - match std::str::from_utf8(slice) { + match str::from_utf8(slice) { Ok(s) => Ok(s), Err(e) => Err(PyErr::from_instance(exc::UnicodeDecodeError::new_utf8( self.py(), @@ -107,10 +107,9 @@ impl PyModule { /// Calls a function in the module. /// This is equivalent to the Python expression: `getattr(module, name)(*args, **kwargs)` - pub fn call(&self, name: &str, args: A, kwargs: K) -> PyResult<&PyObjectRef> + pub fn call(&self, name: &str, args: A, kwargs: Option) -> PyResult<&PyObjectRef> where A: IntoPyTuple, - K: IntoPyDictPointer, { self.getattr(name)?.call(args, kwargs) } diff --git a/src/objects/sequence.rs b/src/objects/sequence.rs index d31bcc48..437abda0 100644 --- a/src/objects/sequence.rs +++ b/src/objects/sequence.rs @@ -311,10 +311,10 @@ impl PyTryFrom for PySequence { mod test { use conversion::{PyTryFrom, ToPyObject}; use instance::AsPyRef; - use objectprotocol::ObjectProtocol; use object::PyObject; + use objectprotocol::ObjectProtocol; use objects::PySequence; - use python::{ToPyPointer, Python}; + use python::{Python, ToPyPointer}; fn get_object() -> PyObject { // Convenience function for getting a single unique object diff --git a/src/python.rs b/src/python.rs index b6c3e539..91c0be4a 100644 --- a/src/python.rs +++ b/src/python.rs @@ -60,23 +60,15 @@ pub trait IntoPyPointer { fn into_ptr(self) -> *mut ffi::PyObject; } -/// Conversion trait that allows various objects to be converted into `PyDict` object pointer. -/// Primary use case for this trait is `call` and `call_method` methods as keywords argument. -pub trait IntoPyDictPointer { - /// Converts self into a `PyDict` object pointer. Whether pointer owned or borrowed - /// depends on implementation. - fn into_dict_ptr(self, py: Python) -> *mut ffi::PyObject; -} - /// Convert `None` into a null pointer. -impl<'p, T> ToPyPointer for Option<&'p T> +impl ToPyPointer for Option where T: ToPyPointer, { #[inline] - default fn as_ptr(&self) -> *mut ffi::PyObject { + fn as_ptr(&self) -> *mut ffi::PyObject { match *self { - Some(t) => t.as_ptr(), + Some(ref t) => t.as_ptr(), None => std::ptr::null_mut(), } } @@ -102,10 +94,12 @@ where T: ToPyPointer, { #[inline] - default fn into_ptr(self) -> *mut ffi::PyObject { + fn into_ptr(self) -> *mut ffi::PyObject { let ptr = self.as_ptr(); - unsafe { - ffi::Py_INCREF(ptr); + if ptr != std::ptr::null_mut() { + unsafe { + ffi::Py_INCREF(ptr); + } } ptr } diff --git a/src/typeob.rs b/src/typeob.rs index c76e378b..6c0846d4 100644 --- a/src/typeob.rs +++ b/src/typeob.rs @@ -250,36 +250,15 @@ where Ok(obj) } - #[cfg(Py_3)] default unsafe fn dealloc(py: Python, obj: *mut ffi::PyObject) { Self::drop(py, obj); - if ffi::PyObject_CallFinalizerFromDealloc(obj) < 0 { - return; - } - - match (*T::type_object()).tp_free { - Some(free) => free(obj as *mut c_void), - None => { - let ty = ffi::Py_TYPE(obj); - if ffi::PyType_IS_GC(ty) != 0 { - ffi::PyObject_GC_Del(obj as *mut c_void); - } else { - ffi::PyObject_Free(obj as *mut c_void); - } - - // For heap types, PyType_GenericAlloc calls INCREF on the type objects, - // so we need to call DECREF here: - if ffi::PyType_HasFeature(ty, ffi::Py_TPFLAGS_HEAPTYPE) != 0 { - ffi::Py_DECREF(ty as *mut ffi::PyObject); - } + #[cfg(Py_3)] + { + if ffi::PyObject_CallFinalizerFromDealloc(obj) < 0 { + return; } } - } - - #[cfg(not(Py_3))] - default unsafe fn dealloc(py: Python, obj: *mut ffi::PyObject) { - Self::drop(py, obj); match (*T::type_object()).tp_free { Some(free) => free(obj as *mut c_void), @@ -357,7 +336,7 @@ where /// Register new type in python object system. #[cfg(not(Py_LIMITED_API))] -pub fn initialize_type<'p, T>(py: Python<'p>, module_name: Option<&str>) -> PyResult<()> +pub fn initialize_type(py: Python, module_name: Option<&str>) -> PyResult<()> where T: PyObjectAlloc + PyTypeInfo, { diff --git a/tests/common.rs b/tests/common.rs index 9b4d3ada..12639a20 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -24,7 +24,7 @@ macro_rules! py_run { d.set_item(stringify!($val), &$val).unwrap(); $py.run(&common::indoc($code), None, Some(d)) .map_err(|e| e.print($py)) - .expect(&common::indoc($code)); + .expect(&common::indoc($code)) }}; } diff --git a/tests/test_class_basics.rs b/tests/test_class_basics.rs index dabe5540..70a4e76a 100644 --- a/tests/test_class_basics.rs +++ b/tests/test_class_basics.rs @@ -16,7 +16,7 @@ fn empty_class() { let py = gil.python(); let typeobj = py.get_type::(); // By default, don't allow creating instances from python. - assert!(typeobj.call(NoArgs, NoArgs).is_err()); + assert!(typeobj.call(NoArgs, None).is_err()); py_assert!(py, typeobj, "typeobj.__name__ == 'EmptyClass'"); } diff --git a/tests/test_class_new.rs b/tests/test_class_new.rs index 3bcb2fc7..6e8d9bd6 100644 --- a/tests/test_class_new.rs +++ b/tests/test_class_new.rs @@ -24,7 +24,7 @@ fn empty_class_with_new() { let typeobj = py.get_type::(); assert!( typeobj - .call(NoArgs, NoArgs) + .call(NoArgs, None) .unwrap() .cast_as::() .is_ok() @@ -53,7 +53,7 @@ fn new_with_one_arg() { let gil = Python::acquire_gil(); let py = gil.python(); let typeobj = py.get_type::(); - let wrp = typeobj.call((42,), NoArgs).unwrap(); + let wrp = typeobj.call((42,), None).unwrap(); let obj = wrp.cast_as::().unwrap(); assert_eq!(obj._data, 42); } @@ -84,7 +84,7 @@ fn new_with_two_args() { let py = gil.python(); let typeobj = py.get_type::(); let wrp = typeobj - .call((10, 20), NoArgs) + .call((10, 20), None) .map_err(|e| e.print(py)) .unwrap(); let obj = wrp.cast_as::().unwrap(); diff --git a/tests/test_gc.rs b/tests/test_gc.rs index d0e281aa..dd656070 100644 --- a/tests/test_gc.rs +++ b/tests/test_gc.rs @@ -263,7 +263,7 @@ fn inheritance_with_new_methods_with_drop() { let py = gil.python(); let _typebase = py.get_type::(); let typeobj = py.get_type::(); - let inst = typeobj.call(NoArgs, NoArgs).unwrap(); + let inst = typeobj.call(NoArgs, None).unwrap(); let obj = SubClassWithDrop::try_from_mut(inst).unwrap(); obj.data = Some(Arc::clone(&drop_called1)); diff --git a/tests/test_inheritance.rs b/tests/test_inheritance.rs index 6823f462..89dec4eb 100644 --- a/tests/test_inheritance.rs +++ b/tests/test_inheritance.rs @@ -62,6 +62,6 @@ fn inheritance_with_new_methods() { let py = gil.python(); let _typebase = py.get_type::(); let typeobj = py.get_type::(); - let inst = typeobj.call(NoArgs, NoArgs).unwrap(); + let inst = typeobj.call(NoArgs, None).unwrap(); py_run!(py, inst, "assert inst.val1 == 10; assert inst.val2 == 5"); } diff --git a/tests/test_methods.rs b/tests/test_methods.rs index 760fb475..7c6667f0 100644 --- a/tests/test_methods.rs +++ b/tests/test_methods.rs @@ -252,5 +252,4 @@ fn meth_args() { inst, "assert inst.get_kwargs(1,2,3,t=1,n=2) == [(1,2,3), {'t': 1, 'n': 2}]" ); - // py_expect_exception!(py, inst, "inst.get_kwarg(100)", TypeError); }