Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb0ee194

Browse files
Merge pull requestRustPython#565 from alexpantyukhin/add_kwarg_handling_to_int
add kwarg handling for int
2 parents56e55e8 +7e2c702 commitb0ee194

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
@@ -17,6 +17,10 @@
1717
assert1>=1.0
1818
assert1<=1.0
1919

20+
# check for argument handling
21+
22+
assertint("101",base=2)==5
23+
2024
# magic methods should only be implemented for other ints
2125

2226
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
returnErr(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)

[8]ページ先頭

©2009-2025 Movatter.jp