stdlib/io.rs: align negative-fd-from-opener exception with CPython

This commit is contained in:
Daniel Watkins
2021-10-28 15:05:55 -04:00
parent 35e56efa65
commit 1ea93a59d5
2 changed files with 1 additions and 5 deletions

4
Lib/test/test_io.py vendored
View File

@@ -864,8 +864,6 @@ class IOTest(unittest.TestCase):
with self.open("non-existent", "r", opener=opener) as f:
self.assertEqual(f.read(), "egg\n")
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_bad_opener_negative_1(self):
# Issue #27066.
def badopener(fname, flags):
@@ -874,8 +872,6 @@ class IOTest(unittest.TestCase):
open('non-existent', 'r', opener=badopener)
self.assertEqual(str(cm.exception), 'opener returned -1')
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_bad_opener_other_negative(self):
# Issue #27066.
def badopener(fname, flags):

View File

@@ -3857,7 +3857,7 @@ mod fileio {
}
let fd = i32::try_from_object(vm, fd)?;
if fd < 0 {
return Err(vm.new_os_error("Negative file descriptor".to_owned()));
return Err(vm.new_value_error(format!("opener returned {}", fd)));
}
fd
} else if let Some(i) = name.payload::<crate::builtins::PyInt>() {