Skip to content

Commit 83386fd

Browse files
committed
Set errno on os.listdir
1 parent 92d0f05 commit 83386fd

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

Lib/test/test_exceptions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,6 @@ def inner():
12011201
self.fail("RecursionError not raised")
12021202
self.assertEqual(wr(), None)
12031203

1204-
@unittest.skip("TODO: RUSTPYTHON")
12051204
def test_errno_ENOTDIR(self):
12061205
# Issue #12802: "not a directory" errors are ENOTDIR even on Windows
12071206
with self.assertRaises(OSError) as cm:

vm/src/stdlib/os.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -413,18 +413,14 @@ fn os_rmdir(path: PyStringRef, dir_fd: DirFd, vm: &VirtualMachine) -> PyResult<(
413413
}
414414

415415
fn os_listdir(path: PyStringRef, vm: &VirtualMachine) -> PyResult {
416-
match fs::read_dir(path.as_str()) {
417-
Ok(iter) => {
418-
let res: PyResult<Vec<PyObjectRef>> = iter
419-
.map(|entry| match entry {
420-
Ok(path) => Ok(vm.ctx.new_str(path.file_name().into_string().unwrap())),
421-
Err(s) => Err(convert_io_error(vm, s)),
422-
})
423-
.collect();
424-
Ok(vm.ctx.new_list(res?))
425-
}
426-
Err(s) => Err(vm.new_os_error(s.to_string())),
427-
}
416+
let res: PyResult<Vec<PyObjectRef>> = fs::read_dir(path.as_str())
417+
.map_err(|err| convert_io_error(vm, err))?
418+
.map(|entry| match entry {
419+
Ok(path) => Ok(vm.ctx.new_str(path.file_name().into_string().unwrap())),
420+
Err(s) => Err(convert_io_error(vm, s)),
421+
})
422+
.collect();
423+
Ok(vm.ctx.new_list(res?))
428424
}
429425

430426
fn bytes_as_osstr<'a>(b: &'a [u8], vm: &VirtualMachine) -> PyResult<&'a ffi::OsStr> {

0 commit comments

Comments
 (0)