Convert hash, hex

This commit is contained in:
Aviv Palivoda
2019-08-31 16:51:04 +03:00
parent 362d0e785d
commit b43af3358b

View File

@@ -301,17 +301,14 @@ fn builtin_hasattr(obj: PyObjectRef, attr: PyStringRef, vm: &VirtualMachine) ->
}
}
fn builtin_hash(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(vm, args, required = [(obj, None)]);
vm._hash(obj).and_then(|v| Ok(vm.new_int(v)))
fn builtin_hash(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult {
vm._hash(&obj).and_then(|v| Ok(vm.new_int(v)))
}
// builtin_help
fn builtin_hex(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(vm, args, required = [(number, Some(vm.ctx.int_type()))]);
let n = objint::get_value(number);
fn builtin_hex(number: PyIntRef, vm: &VirtualMachine) -> PyResult {
let n = number.as_bigint();
let s = if n.is_negative() {
format!("-0x{:x}", n.abs())
} else {