Skip to content

Commit 507f7bd

Browse files
committed
Fix for os open (optional params not allowed)
1 parent c011db2 commit 507f7bd

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

tests/snippets/os_open.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import os
22

3-
assert os.open('README.md') > 0
3+
assert os.open('README.md', 0) > 0
44

tests/snippets/os_static.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
assert os.O_RDONLY == 0
44
assert os.O_WRONLY == 1
55
assert os.O_RDWR == 2
6-
assert os.O_NONBLOCK == 3
6+
assert os.O_NONBLOCK == 4
77
assert os.O_APPEND == 8
88
assert os.O_CREAT == 512

vm/src/stdlib/os.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,13 @@ pub fn os_open(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
1616
arg_check!(
1717
vm,
1818
args,
19-
required = [(name, Some(vm.ctx.str_type()))],
20-
optional = [(mode, Some(vm.ctx.int_type()))]
19+
required = [
20+
(name, Some(vm.ctx.str_type())),
21+
(mode, Some(vm.ctx.int_type()))
22+
]
2123
);
2224

23-
let mode = if let Some(m) = mode {
24-
objint::get_value(m)
25-
} else {
26-
0.to_bigint().unwrap()
27-
};
28-
29-
let handle = match mode.to_u16().unwrap() {
25+
let handle = match objint::get_value(mode).to_u16().unwrap() {
3026
0 => OpenOptions::new().read(true).open(objstr::get_value(&name)),
3127
1 => OpenOptions::new()
3228
.write(true)
@@ -53,7 +49,7 @@ pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
5349
ctx.set_attr(&py_mod, "O_RDONLY", ctx.new_int(0.to_bigint().unwrap()));
5450
ctx.set_attr(&py_mod, "O_WRONLY", ctx.new_int(1.to_bigint().unwrap()));
5551
ctx.set_attr(&py_mod, "O_RDWR", ctx.new_int(2.to_bigint().unwrap()));
56-
ctx.set_attr(&py_mod, "O_NONBLOCK", ctx.new_int(3.to_bigint().unwrap()));
52+
ctx.set_attr(&py_mod, "O_NONBLOCK", ctx.new_int(4.to_bigint().unwrap()));
5753
ctx.set_attr(&py_mod, "O_APPEND", ctx.new_int(8.to_bigint().unwrap()));
5854
ctx.set_attr(&py_mod, "O_CREAT", ctx.new_int(512.to_bigint().unwrap()));
5955
py_mod

0 commit comments

Comments
 (0)