MCPcopy Index your code
hub / github.com/RustPython/RustPython / round

Function round

crates/vm/src/stdlib/builtins.rs:1049–1068  ·  view source on GitHub ↗
(RoundArgs { number, ndigits }: RoundArgs, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

1047
1048 #[pyfunction]
1049 fn round(RoundArgs { number, ndigits }: RoundArgs, vm: &VirtualMachine) -> PyResult {
1050 let meth = vm
1051 .get_special_method(&number, identifier!(vm, __round__))?
1052 .ok_or_else(|| {
1053 vm.new_type_error(format!(
1054 "type {} doesn't define __round__",
1055 number.class().name()
1056 ))
1057 })?;
1058 match ndigits.flatten() {
1059 Some(obj) => {
1060 let ndigits = obj.try_index(vm)?;
1061 meth.invoke((ndigits,), vm)
1062 }
1063 None => {
1064 // without a parameter, the result type is coerced to int
1065 meth.invoke((), vm)
1066 }
1067 }
1068 }
1069
1070 #[pyfunction]
1071 fn setattr(

Callers 15

__new__Method · 0.85
_fromtimestampMethod · 0.85
_as_intFunction · 0.85
setframerateMethod · 0.85
create_pax_headerMethod · 0.85
__round__Method · 0.85
__repr__Method · 0.85
assertAlmostEqualMethod · 0.85
assertNotAlmostEqualMethod · 0.85
taskMethod · 0.85
task2Method · 0.85

Calls 5

ok_or_elseMethod · 0.80
get_special_methodMethod · 0.80
try_indexMethod · 0.80
flattenMethod · 0.45
invokeMethod · 0.45

Tested by 15

taskMethod · 0.68
task2Method · 0.68
testConversionsMethod · 0.68
testRoundMethod · 0.68
test_computationsMethod · 0.68
as_hoursMethod · 0.68
test_roundMethod · 0.68
test_roundMethod · 0.68
test_round_largeMethod · 0.68
test_bug_27936Method · 0.68
test_initMethod · 0.68