mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 11:14:38 +08:00
Merge pull request #565 from alexpantyukhin/add_kwarg_handling_to_int
add kwarg handling for int
This commit is contained in:
2 files changed
+8
-2
No files matched your search
@@ -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
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in new issue
Block a user