diff --git a/tests/snippets/basic_types.py b/tests/snippets/basic_types.py index b9dc22b27..968b9fac9 100644 --- a/tests/snippets/basic_types.py +++ b/tests/snippets/basic_types.py @@ -33,3 +33,4 @@ try: except TypeError: pass +assert int() == 0 diff --git a/vm/src/obj/objint.rs b/vm/src/obj/objint.rs index d98406a3c..8c7731475 100644 --- a/vm/src/obj/objint.rs +++ b/vm/src/obj/objint.rs @@ -13,11 +13,19 @@ fn int_repr(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { } fn int_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { - let ref cls = args.args[0]; + arg_check!( + vm, + args, + required = [(cls, None)], + optional = [(val_option, None)] + ); if !objtype::issubclass(cls, vm.ctx.int_type()) { return Err(vm.new_type_error(format!("{:?} is not a subtype of int", cls))); } - let val = to_int(vm, &args.args[1].clone())?; + let val = match val_option { + Some(val) => to_int(vm, val)?, + None => 0, + }; Ok(PyObject::new( PyObjectKind::Integer { value: val }, cls.clone(),