Replace vm.obj_len to obj.length

This commit is contained in:
ChJR
2021-10-20 02:33:46 +09:00
parent 6b14756542
commit 32e693f234
2 changed files with 6 additions and 10 deletions

View File

@@ -151,7 +151,12 @@ impl PyObjectRef {
// int PyObject_TypeCheck(PyObject *o, PyTypeObject *type)
pub fn length(&self, vm: &VirtualMachine) -> PyResult<usize> {
vm.obj_len(self)
vm.obj_len_opt(self).unwrap_or_else(|| {
Err(vm.new_type_error(format!(
"object of type '{}' has no len()",
self.class().name()
)))
})
}
pub fn length_hint(

View File

@@ -1920,15 +1920,6 @@ impl VirtualMachine {
})
}
pub fn obj_len(&self, obj: &PyObjectRef) -> PyResult<usize> {
self.obj_len_opt(obj).unwrap_or_else(|| {
Err(self.new_type_error(format!(
"object of type '{}' has no len()",
obj.class().name()
)))
})
}
pub fn length_hint(&self, iter: PyObjectRef) -> PyResult<Option<usize>> {
if let Some(len) = self.obj_len_opt(&iter) {
match len {