Merge pull request #1015 from mkurnikov/empty-exception-message

Make empty exception message format compatible with CPython
This commit is contained in:
Windel Bouwman authored and GitHub committed 2019-06-04 15:52:47 +02:00
commit 0c9d3c8918
1 file changed
+7 -3
+7 -3
View File
@@ -12,7 +12,8 @@ fn exception_init(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
let msg = if args.args.len() > 1 {
args.args[1].clone()
} else {
vm.new_str("No msg".to_string())
let empty_string = String::default();
vm.new_str(empty_string)
};
let traceback = vm.ctx.new_list(Vec::new());
vm.set_attr(&zelf, "msg", msg)?;
@@ -132,8 +133,11 @@ fn exception_str(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
} else {
panic!("Error message must be set");
};
let s = format!("{}: {}", exc.class().name, msg);
Ok(vm.new_str(s))
let mut exc_repr = exc.class().name.clone();
if !msg.is_empty() {
&exc_repr.push_str(&format!(": {}", msg));
}
Ok(vm.new_str(exc_repr))
}
#[derive(Debug)]