From 1ea93a59d5f393f243f9ff96f414472cf43512bc Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Thu, 28 Oct 2021 15:05:55 -0400 Subject: [PATCH] stdlib/io.rs: align negative-fd-from-opener exception with CPython --- Lib/test/test_io.py | 4 ---- vm/src/stdlib/io.rs | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index a8d5273bd6..02c5bb0fdc 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -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): diff --git a/vm/src/stdlib/io.rs b/vm/src/stdlib/io.rs index b2ab2eb117..a191177078 100644 --- a/vm/src/stdlib/io.rs +++ b/vm/src/stdlib/io.rs @@ -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::() {