Skip to content

Commit d6d305f

Browse files
committed
2 parents d88167b + f209929 commit d6d305f

File tree

5 files changed

+17
-1
lines changed

5 files changed

+17
-1
lines changed

tests/snippets/basic_types.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from testutils import assert_raises
2+
3+
14
# Spec: https://docs.python.org/2/library/types.html
25
print(None)
36
# TypeType
@@ -36,6 +39,9 @@
3639
except TypeError:
3740
pass
3841

42+
with assert_raises(ValueError):
43+
bytes(-1)
44+
3945
a = bytearray([1, 2, 3])
4046
# assert a[1] == 2
4147

tests/snippets/exit.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from testutils import assert_raises
2+
3+
with assert_raises(SystemExit):
4+
exit()

vm/src/builtins.rs

+1
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,7 @@ pub fn make_module(vm: &VirtualMachine, module: PyObjectRef) {
883883
"UserWarning" => ctx.exceptions.user_warning.clone(),
884884

885885
"KeyboardInterrupt" => ctx.exceptions.keyboard_interrupt.clone(),
886+
"SystemExit" => ctx.exceptions.system_exit.clone(),
886887
});
887888
}
888889

vm/src/exceptions.rs

+3
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ pub struct ExceptionZoo {
252252
pub user_warning: PyClassRef,
253253

254254
pub keyboard_interrupt: PyClassRef,
255+
pub system_exit: PyClassRef,
255256
}
256257

257258
impl ExceptionZoo {
@@ -303,6 +304,7 @@ impl ExceptionZoo {
303304
let user_warning = create_type("UserWarning", &type_type, &warning);
304305

305306
let keyboard_interrupt = create_type("KeyboardInterrupt", &type_type, &base_exception_type);
307+
let system_exit = create_type("SystemExit", &type_type, &base_exception_type);
306308

307309
ExceptionZoo {
308310
arithmetic_error,
@@ -347,6 +349,7 @@ impl ExceptionZoo {
347349
reference_error,
348350
user_warning,
349351
keyboard_interrupt,
352+
system_exit,
350353
}
351354
}
352355
}

vm/src/obj/objbyteinner.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ impl ByteInnerNewOptions {
117117
let value = if let OptionalArg::Present(ival) = self.val_option {
118118
match_class!(match ival.clone() {
119119
i @ PyInt => {
120-
let size = objint::get_value(&i.into_object()).to_usize().unwrap();
120+
let size = objint::get_value(&i.into_object())
121+
.to_usize()
122+
.ok_or_else(|| vm.new_value_error("negative count".to_string()))?;
121123
Ok(vec![0; size])
122124
}
123125
_l @ PyString => {

0 commit comments

Comments
 (0)