Merge pull request #565 from alexpantyukhin/add_kwarg_handling_to_int

add kwarg handling for int
This commit is contained in:
Windel Bouwman authored and GitHub committed 2019-02-28 07:36:08 +01:00
commit b0ee1947c7
2 files changed
+8 -2

No files matched your search

+4
View File
@@ -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
+4 -2
View File
@@ -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(),