Skip to content

Commit 10f0ef3

Browse files
committed
Implement no-args int() construction
1 parent 82226bf commit 10f0ef3

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

tests/snippets/basic_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@
3333
except TypeError:
3434
pass
3535

36+
assert int() == 0

vm/src/obj/objint.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,19 @@ fn int_repr(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
1313
}
1414

1515
fn int_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
16-
let ref cls = args.args[0];
16+
arg_check!(
17+
vm,
18+
args,
19+
required = [(cls, None)],
20+
optional = [(val_option, None)]
21+
);
1722
if !objtype::issubclass(cls, vm.ctx.int_type()) {
1823
return Err(vm.new_type_error(format!("{:?} is not a subtype of int", cls)));
1924
}
20-
let val = to_int(vm, &args.args[1].clone())?;
25+
let val = match val_option {
26+
Some(val) => to_int(vm, val)?,
27+
None => 0,
28+
};
2129
Ok(PyObject::new(
2230
PyObjectKind::Integer { value: val },
2331
cls.clone(),

0 commit comments

Comments
 (0)