Allow empty return type for property setter

This commit is contained in:
Jeong YunWon
2019-12-27 00:20:27 +09:00
parent 57b6bf3e64
commit 278f0fffca
2 changed files with 10 additions and 3 deletions

View File

@@ -84,9 +84,8 @@ impl PyBaseException {
}
#[pyproperty(name = "__traceback__", setter)]
fn set_traceback(&self, traceback: Option<PyTracebackRef>, vm: &VirtualMachine) -> PyResult {
fn set_traceback(&self, traceback: Option<PyTracebackRef>, _vm: &VirtualMachine) {
self.traceback.replace(traceback);
Ok(vm.get_none())
}
#[pyproperty(name = "__cause__")]

View File

@@ -252,6 +252,11 @@ pub struct PropertyBuilder<'a> {
setter: Option<PyObjectRef>,
}
pub trait PropertySetterResult {}
impl PropertySetterResult for PyResult {}
impl PropertySetterResult for () {}
impl<'a> PropertyBuilder<'a> {
pub fn new(ctx: &'a PyContext) -> Self {
Self {
@@ -270,7 +275,10 @@ impl<'a> PropertyBuilder<'a> {
}
}
pub fn add_setter<I, V, F: IntoPyNativeFunc<(I, V), PyResult>>(self, func: F) -> Self {
pub fn add_setter<I, V, R: PropertySetterResult, F: IntoPyNativeFunc<(I, V), R>>(
self,
func: F,
) -> Self {
let func = self.ctx.new_rustfunc(func);
Self {
ctx: self.ctx,