mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
Improve code quality
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user