diff --git a/tests/snippets/ints.py b/tests/snippets/ints.py index 3bf91491d..2d36afcb6 100644 --- a/tests/snippets/ints.py +++ b/tests/snippets/ints.py @@ -17,6 +17,10 @@ assert not 1 < 1.0 assert 1 >= 1.0 assert 1 <= 1.0 +# check for argument handling + +assert int("101", base=2) == 5 + # magic methods should only be implemented for other ints assert (1).__eq__(1) == True diff --git a/vm/src/obj/objint.rs b/vm/src/obj/objint.rs index 8c240fba3..7e22f19be 100644 --- a/vm/src/obj/objint.rs +++ b/vm/src/obj/objint.rs @@ -48,8 +48,10 @@ fn int_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { return Err(vm.new_type_error(format!("{:?} is not a subtype of int", cls))); } - // TODO: extract kwargs: - let base = 10; + let base = match args.get_optional_kwarg("base") { + Some(argument) => get_value(&argument).to_u32().unwrap(), + None => 10, + }; let val = match val_option { Some(val) => to_int(vm, val, base)?, None => Zero::zero(),