Skip to content

Commit 7c86523

Browse files
committed
Reuse cls
1 parent c2ea003 commit 7c86523

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

crates/vm/src/builtins/super.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,10 @@ impl Representable for PySuper {
239239
}
240240

241241
fn super_check(ty: PyTypeRef, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyTypeRef> {
242-
let is_type = match obj.clone().downcast::<PyType>() {
242+
let typ = match obj.clone().downcast::<PyType>() {
243243
Ok(cls) if cls.fast_issubclass(&ty) => return Ok(cls),
244-
Ok(_) => true,
245-
Err(_) => false,
244+
Ok(cls) => Some(cls),
245+
Err(_) => None,
246246
};
247247

248248
if obj.fast_isinstance(&ty) {
@@ -257,13 +257,9 @@ fn super_check(ty: PyTypeRef, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult
257257
return Ok(cls);
258258
}
259259

260-
let (type_or_instance, obj_str) = if is_type {
261-
// SAFETY: This is will always be successful as we already checked at the begining of
262-
// the function.
263-
let typ = unsafe { obj.downcast::<PyType>().unwrap_unchecked() };
264-
("type", typ.name().to_owned())
265-
} else {
266-
("instance of", obj.class().name().to_owned())
260+
let (type_or_instance, obj_str) = match typ {
261+
Some(t) => ("type", t.name().to_owned()),
262+
None => ("instance of", obj.class().name().to_owned()),
267263
};
268264

269265
Err(vm.new_type_error(format!(

0 commit comments

Comments
 (0)