Skip to content

Commit d806a19

Browse files
add kwarg handling for int
1 parent d6242ac commit d806a19

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

tests/snippets/ints.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
assert 1 >= 1.0
1616
assert 1 <= 1.0
1717

18+
# check for argument handling
19+
20+
assert int("101", base=2) == 5
21+
1822
# magic methods should only be implemented for other ints
1923

2024
assert (1).__eq__(1) == True

vm/src/obj/objint.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ fn int_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
4848
return Err(vm.new_type_error(format!("{:?} is not a subtype of int", cls)));
4949
}
5050

51-
// TODO: extract kwargs:
52-
let base = 10;
51+
let base = match args.get_optional_kwarg("base") {
52+
Some(argument) => get_value(&argument).to_u32().unwrap(),
53+
None => 10
54+
};
5355
let val = match val_option {
5456
Some(val) => to_int(vm, val, base)?,
5557
None => Zero::zero(),

0 commit comments

Comments
 (0)