Skip to content

Commit 47a3bda

Browse files
committed
Fill OSError attributes
1 parent 3301220 commit 47a3bda

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

Lib/test/test_exception_hierarchy.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import unittest
66
import errno
77
from errno import EEXIST
8+
import sys
89

910

1011
class SubOSError(OSError):
@@ -130,8 +131,8 @@ def test_windows_error(self):
130131
else:
131132
self.assertNotIn('winerror', dir(OSError))
132133

133-
# TODO: RUSTPYTHON
134-
@unittest.expectedFailure
134+
@unittest.skip("TODO: RUSTPYTHON")
135+
@unittest.skipIf(sys.platform == 'win32', 'winerror not filled yet')
135136
def test_posix_error(self):
136137
e = OSError(EEXIST, "File already exists", "foo.txt")
137138
self.assertEqual(e.errno, EEXIST)

Lib/test/test_fileio.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,6 @@ class PyAutoFileTests(AutoFileTests, unittest.TestCase):
391391
FileIO = _pyio.FileIO
392392
modulename = '_pyio'
393393

394-
# TODO: RUSTPYTHON
395-
@unittest.expectedFailure
396394
def testOpendir(self):
397395
super().testOpendir()
398396

Lib/test/test_subprocess.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,8 +1547,6 @@ def test_failed_child_execute_fd_leak(self):
15471547
fds_after_exception = os.listdir(fd_directory)
15481548
self.assertEqual(fds_before_popen, fds_after_exception)
15491549

1550-
# TODO: RUSTPYTHON
1551-
@unittest.expectedFailure
15521550
@unittest.skipIf(mswindows, "behavior currently not supported on Windows")
15531551
def test_file_not_found_includes_filename(self):
15541552
with self.assertRaises(FileNotFoundError) as c:

vm/src/exceptions.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ pub(super) mod types {
12601260
os_error,
12611261
"Base class for I/O related errors.",
12621262
os_error_new,
1263-
base_exception_init,
1263+
os_error_init,
12641264
}
12651265
#[cfg(not(target_arch = "wasm32"))]
12661266
fn os_error_optional_new(
@@ -1297,9 +1297,19 @@ pub(super) mod types {
12971297
fn os_error_new(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
12981298
PyBaseException::slot_new(cls, args, vm)
12991299
}
1300+
fn os_error_init(zelf: PyObjectRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult<()> {
1301+
if args.args.len() >= 3 {
1302+
zelf.set_attr("filename", args.args[2].clone(), vm)?;
1303+
if args.args.len() >= 4 {
1304+
zelf.set_attr("filename2", args.args[args.args.len() - 1].clone(), vm)?;
1305+
}
1306+
}
13001307

1301-
fn base_exception_init(zelf: PyObjectRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult<()> {
1302-
PyBaseException::init(zelf, args, vm)
1308+
let mut new_args = args;
1309+
if new_args.args.len() >= 2 {
1310+
new_args.args.truncate(2);
1311+
}
1312+
PyBaseException::init(zelf, new_args, vm)
13031313
}
13041314

13051315
define_exception! {

0 commit comments

Comments
 (0)