mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 03:04:38 +08:00
clean up name() usage
This commit is contained in:
1 parent
8d38bf8ded
commit
ccc8f7ed37
3 files changed
+10
-14
No files matched your search
@@ -1653,10 +1653,7 @@ mod tests {
|
||||
let translated = text.translate(translated, vm).unwrap();
|
||||
assert_eq!(translated, "🎅xda".to_owned());
|
||||
let translated = text.translate(vm.ctx.new_int(3).into(), vm);
|
||||
assert_eq!(
|
||||
translated.unwrap_err().class().name().deref(),
|
||||
"TypeError".to_owned()
|
||||
);
|
||||
assert_eq!("TypeError", &*translated.unwrap_err().class().name(),);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -84,12 +84,12 @@ fn spec_format_bytes(
|
||||
}
|
||||
},
|
||||
CFormatType::Float(_) => {
|
||||
let type_name = obj.class().name().to_string();
|
||||
let class = obj.class().to_owned();
|
||||
let value = ArgIntoFloat::try_from_object(vm, obj).map_err(|e| {
|
||||
if e.fast_isinstance(vm.ctx.exceptions.type_error) {
|
||||
// formatfloat in bytesobject.c generates its own specific exception
|
||||
// text in this case, mirror it here.
|
||||
vm.new_type_error(format!("float argument required, not {type_name}"))
|
||||
vm.new_type_error(format!("float argument required, not {}", class.name()))
|
||||
} else {
|
||||
e
|
||||
}
|
||||
|
||||
@@ -611,14 +611,13 @@ impl PyObject {
|
||||
None
|
||||
};
|
||||
let cls_is_weakref = typ.is(vm.ctx.types.weakref_type);
|
||||
self.weak_ref_list()
|
||||
.map(|wrl| wrl.add(self, typ, cls_is_weakref, callback, dict))
|
||||
.ok_or_else(|| {
|
||||
vm.new_type_error(format!(
|
||||
"cannot create weak reference to '{}' object",
|
||||
self.class().name()
|
||||
))
|
||||
})
|
||||
let wrl = self.weak_ref_list().ok_or_else(|| {
|
||||
vm.new_type_error(format!(
|
||||
"cannot create weak reference to '{}' object",
|
||||
self.class().name()
|
||||
))
|
||||
})?;
|
||||
Ok(wrl.add(self, typ, cls_is_weakref, callback, dict))
|
||||
}
|
||||
|
||||
pub fn downgrade(
|
||||
|
||||
Reference in new issue
Block a user