mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
Simplify calling __hash__ method
This commit is contained in:
@@ -9,6 +9,7 @@ use super::super::vm::VirtualMachine;
|
||||
use super::objbool;
|
||||
use super::objiter;
|
||||
use super::objstr;
|
||||
use super::objint;
|
||||
use super::objtype;
|
||||
use num_bigint::BigInt;
|
||||
use std::collections::HashMap;
|
||||
@@ -32,20 +33,11 @@ fn perform_action_with_hash(
|
||||
&PyObjectRef,
|
||||
) -> PyResult,
|
||||
) -> PyResult {
|
||||
let hash_result: PyResult = vm.call_method(item, "__hash__", vec![]);
|
||||
match hash_result {
|
||||
Ok(hash_object) => {
|
||||
let hash = hash_object.borrow();
|
||||
match hash.payload {
|
||||
PyObjectPayload::Integer { ref value } => {
|
||||
let key = value.clone();
|
||||
f(vm, elements, key, item)
|
||||
}
|
||||
_ => Err(vm.new_type_error(format!("__hash__ method should return an integer"))),
|
||||
}
|
||||
}
|
||||
Err(error) => Err(error),
|
||||
}
|
||||
let hash: PyObjectRef = vm.call_method(item, "__hash__", vec![])?;
|
||||
|
||||
let hash_value = objint::get_value(&hash);
|
||||
let key = hash_value.clone();
|
||||
f(vm, elements, key, item)
|
||||
}
|
||||
|
||||
fn insert_into_set(
|
||||
|
||||
Reference in New Issue
Block a user