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

Commit3469f5c

Browse files
add kwarg handling for int
1 parentd6242ac commit3469f5c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-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
assert1>=1.0
1616
assert1<=1.0
1717

18+
# check for argument handling
19+
20+
assertint("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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ 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+
//Some(argument) => to_int(v).to_u32().unwrap(),
54+
55+
None =>10
56+
};
5357
let val =match val_option{
5458
Some(val) =>to_int(vm, val, base)?,
5559
None =>Zero::zero(),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp