Skip to content

Commit 8bdc766

Browse files
Use name field directly
1 parent 6474a4a commit 8bdc766

File tree

9 files changed

+22
-18
lines changed

9 files changed

+22
-18
lines changed

vm/src/builtins.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ fn builtin_len(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
368368
Ok(value) => vm.invoke(value, PyFuncArgs::default()),
369369
Err(..) => Err(vm.new_type_error(format!(
370370
"object of type '{}' has no method {:?}",
371-
obj.class(),
371+
obj.class().name,
372372
len_method_name
373373
))),
374374
}
@@ -605,7 +605,9 @@ fn builtin_reversed(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
605605
match vm.get_method(obj.clone(), "__reversed__") {
606606
Ok(value) => vm.invoke(value, PyFuncArgs::default()),
607607
// TODO: fallback to using __len__ and __getitem__, if object supports sequence protocol
608-
Err(..) => Err(vm.new_type_error(format!("'{}' object is not reversible", obj.class()))),
608+
Err(..) => {
609+
Err(vm.new_type_error(format!("'{}' object is not reversible", obj.class().name)))
610+
}
609611
}
610612
}
611613
// builtin_reversed

vm/src/exceptions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn exception_str(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
7676
} else {
7777
panic!("Error message must be set");
7878
};
79-
let s = format!("{}: {}", exc.class(), msg);
79+
let s = format!("{}: {}", exc.class().name, msg);
8080
Ok(vm.new_str(s))
8181
}
8282

vm/src/frame.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,18 +1091,20 @@ impl Frame {
10911091
fn _in(&self, vm: &VirtualMachine, needle: PyObjectRef, haystack: PyObjectRef) -> PyResult {
10921092
match self._membership(vm, needle, &haystack) {
10931093
Ok(found) => Ok(found),
1094-
Err(_) => {
1095-
Err(vm.new_type_error(format!("{} has no __contains__ method", haystack.class())))
1096-
}
1094+
Err(_) => Err(vm.new_type_error(format!(
1095+
"{} has no __contains__ method",
1096+
haystack.class().name
1097+
))),
10971098
}
10981099
}
10991100

11001101
fn _not_in(&self, vm: &VirtualMachine, needle: PyObjectRef, haystack: PyObjectRef) -> PyResult {
11011102
match self._membership(vm, needle, &haystack) {
11021103
Ok(found) => Ok(vm.ctx.new_bool(!objbool::get_value(&found))),
1103-
Err(_) => {
1104-
Err(vm.new_type_error(format!("{} has no __contains__ method", haystack.class())))
1105-
}
1104+
Err(_) => Err(vm.new_type_error(format!(
1105+
"{} has no __contains__ method",
1106+
haystack.class().name
1107+
))),
11061108
}
11071109
}
11081110

vm/src/obj/objfloat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl PyFloatRef {
190190
}
191191
}
192192
} else {
193-
return Err(vm.new_type_error(format!("can't convert {} to float", arg.class())));
193+
return Err(vm.new_type_error(format!("can't convert {} to float", arg.class().name)));
194194
};
195195
PyFloat { value }.into_ref_with_type(vm, cls)
196196
}

vm/src/obj/objint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ pub fn to_int(vm: &VirtualMachine, obj: &PyObjectRef, base: u32) -> PyResult<Big
414414
} else {
415415
return Err(vm.new_type_error(format!(
416416
"int() argument must be a string or a number, not '{}'",
417-
obj.class()
417+
obj.class().name
418418
)));
419419
};
420420
Ok(val)

vm/src/obj/objobject.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fn object_setattr(
120120
} else {
121121
Err(vm.new_attribute_error(format!(
122122
"'{}' object has no attribute '{}'",
123-
obj.class(),
123+
obj.class().name,
124124
&attr_name.value
125125
)))
126126
}
@@ -141,7 +141,7 @@ fn object_delattr(obj: PyObjectRef, attr_name: PyStringRef, vm: &VirtualMachine)
141141
} else {
142142
Err(vm.new_attribute_error(format!(
143143
"'{}' object has no attribute '{}'",
144-
obj.class(),
144+
obj.class().name,
145145
&attr_name.value
146146
)))
147147
}
@@ -155,7 +155,7 @@ fn object_str(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
155155
fn object_repr(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
156156
arg_check!(vm, args, required = [(obj, Some(vm.ctx.object()))]);
157157
let address = obj.get_id();
158-
Ok(vm.new_str(format!("<{} object at 0x{:x}>", obj.class(), address)))
158+
Ok(vm.new_str(format!("<{} object at 0x{:x}>", obj.class().name, address)))
159159
}
160160

161161
pub fn object_dir(obj: PyObjectRef, vm: &VirtualMachine) -> PyList {

vm/src/obj/objsuper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn super_new(
114114
if !objtype::isinstance(py_type.as_object(), &vm.get_type()) {
115115
return Err(vm.new_type_error(format!(
116116
"super() argument 1 must be type, not {}",
117-
py_type.class()
117+
py_type.class().name
118118
)));
119119
}
120120

vm/src/pyobject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl fmt::Display for PyObject<dyn PyObjectPayload> {
101101
if let Some(PyModule { ref name, .. }) = self.payload::<PyModule>() {
102102
return write!(f, "module '{}'", name);
103103
}
104-
write!(f, "'{}' object", self.class())
104+
write!(f, "'{}' object", self.class().name)
105105
}
106106
}
107107

vm/src/vm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ impl VirtualMachine {
177177
self.new_type_error(format!(
178178
"Unsupported operand types for '{}': '{}' and '{}'",
179179
op,
180-
a.class(),
181-
b.class()
180+
a.class().name,
181+
b.class().name
182182
))
183183
}
184184

0 commit comments

Comments
 (0)