Merge pull request #2111 from youknowone/avoid-pystr

avoid to_pystr to generate type name
This commit is contained in:
Jeong YunWon
2020-08-14 05:53:52 +09:00
committed by GitHub
4 changed files with 8 additions and 8 deletions

View File

@@ -910,9 +910,10 @@ fn call_object_format(
let result = vm.call_method(&argument, "__format__", vec![returned_type])?;
if !objtype::isinstance(&result, &vm.ctx.types.str_type) {
let result_type = result.class();
let actual_type = vm.to_pystr(&result_type)?;
return Err(vm.new_type_error(format!("__format__ must return a str, not {}", actual_type)));
return Err(vm.new_type_error(format!(
"__format__ must return a str, not {}",
&result.class().name
)));
}
Ok(result)
}

View File

@@ -128,8 +128,8 @@ impl PyFuncArgs {
if isinstance(&kwarg, &ty) {
Ok(Some(kwarg))
} else {
let expected_ty_name = vm.to_pystr(&ty)?;
let actual_ty_name = vm.to_pystr(&kwarg.class())?;
let expected_ty_name = &ty.name;
let actual_ty_name = &kwarg.class().name;
Err(vm.new_type_error(format!(
"argument of type {} is required for named parameter `{}` (got: {})",
expected_ty_name, key, actual_ty_name

View File

@@ -155,8 +155,7 @@ impl PyBool {
#[pyslot]
fn tp_new(zelf: PyObjectRef, x: OptionalArg<PyObjectRef>, vm: &VirtualMachine) -> PyResult {
if !objtype::isinstance(&zelf, &vm.ctx.types.type_type) {
let zelf_typ = zelf.class();
let actual_type = vm.to_pystr(&zelf_typ)?;
let actual_type = &zelf.class().name;
return Err(vm.new_type_error(format!(
"requires a 'type' object but received a '{}'",
actual_type

View File

@@ -194,7 +194,7 @@ impl PyBaseObject {
Ok(())
}
Err(value) => {
let type_repr = vm.to_pystr(&value.class())?;
let type_repr = &value.class().name;
Err(vm.new_type_error(format!(
"__class__ must be set to a class, not '{}' object",
type_repr