Improve code quality

This commit is contained in:
ChJR
2022-07-16 17:09:27 +09:00
parent 9d9f9d364b
commit 4bf5644712
2 changed files with 20 additions and 19 deletions

View File

@@ -67,18 +67,20 @@ impl Constructor for PyClassMethod {
type Args = PyObjectRef;
fn py_new(cls: PyTypeRef, callable: Self::Args, vm: &VirtualMachine) -> PyResult {
let result: PyResult<PyObjectRef> = PyClassMethod {
callable: PyMutex::new(callable.clone()),
let doc = callable.get_attr("__doc__", vm);
let result = PyClassMethod {
callable: PyMutex::new(callable),
}
.into_ref_with_type(vm, cls)
.map(Into::into);
.into_ref_with_type(vm, cls)?;
let obj = PyObjectRef::from(result);
let doc: PyResult<PyObjectRef> = callable.get_attr("__doc__", vm);
let doc = vm.unwrap_pyresult(doc);
let obj = vm.unwrap_pyresult(result.clone());
match doc {
Err(_) => None,
Ok(doc) => Some(obj.set_attr("__doc__", doc, vm)),
};
obj.set_attr("__doc__", doc, vm)?;
result
Ok(obj)
}
}

View File

@@ -41,18 +41,17 @@ impl Constructor for PyStaticMethod {
type Args = PyObjectRef;
fn py_new(cls: PyTypeRef, callable: Self::Args, vm: &VirtualMachine) -> PyResult {
let result: PyResult<PyObjectRef> = PyStaticMethod {
callable: callable.clone(),
}
.into_ref_with_type(vm, cls)
.map(Into::into);
let doc = callable.get_attr("__doc__", vm);
let doc: PyResult<PyObjectRef> = callable.get_attr("__doc__", vm);
let doc = vm.unwrap_pyresult(doc);
let obj = vm.unwrap_pyresult(result.clone());
let result = PyStaticMethod { callable }.into_ref_with_type(vm, cls)?;
let obj = PyObjectRef::from(result);
obj.set_attr("__doc__", doc, vm)?;
result
match doc {
Err(_) => None,
Ok(doc) => Some(obj.set_attr("__doc__", doc, vm)),
};
Ok(obj)
}
}