diff --git a/Lib/test/test_bz2.py b/Lib/test/test_bz2.py index cc7122f15..07db98ed5 100644 --- a/Lib/test/test_bz2.py +++ b/Lib/test/test_bz2.py @@ -740,7 +740,6 @@ class BZ2FileTest(BaseTest): self.assertEqual(f.read(), self.DATA) self.assertEqual(f.name, str_filename) - @unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: != 'Z:\\TEMP\\tmphoipjcen' def testOpenPathLikeFilename(self): filename = FakePath(self.filename) with BZ2File(filename, "wb") as f: diff --git a/Lib/test/test_lzma.py b/Lib/test/test_lzma.py index a433f0c61..eebe6370f 100644 --- a/Lib/test/test_lzma.py +++ b/Lib/test/test_lzma.py @@ -555,7 +555,6 @@ class FileTestCase(unittest.TestCase): self.assertIsInstance(f, LZMAFile) self.assertEqual(f.mode, "wb") - @unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: != '@test_23396_tmp챈' def test_init_with_PathLike_filename(self): filename = FakePath(TESTFN) with TempFile(filename, COMPRESSED_XZ): @@ -1438,7 +1437,6 @@ class OpenTestCase(unittest.TestCase): with lzma.open(TESTFN, "rb") as f: self.assertEqual(f.read(), INPUT * 2) - @unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: != '@test_23396_tmp챈' def test_with_pathlike_filename(self): filename = FakePath(TESTFN) with TempFile(filename): diff --git a/crates/vm/src/stdlib/_io.rs b/crates/vm/src/stdlib/_io.rs index 418431a73..7ffdcad4d 100644 --- a/crates/vm/src/stdlib/_io.rs +++ b/crates/vm/src/stdlib/_io.rs @@ -121,8 +121,8 @@ mod _io { convert::ToPyObject, exceptions::cstring_error, function::{ - ArgBytesLike, ArgIterable, ArgMemoryBuffer, ArgSize, Either, FuncArgs, IntoFuncArgs, - OptionalArg, OptionalOption, PySetterValue, + ArgBytesLike, ArgIterable, ArgMemoryBuffer, ArgSize, Either, FsPath, FuncArgs, + IntoFuncArgs, OptionalArg, OptionalOption, PySetterValue, }, protocol::{ BufferDescriptor, BufferMethods, BufferResizeGuard, PyBuffer, PyIterReturn, VecBuffer, @@ -5069,6 +5069,15 @@ mod _io { } } + // Match CPython's _pyio.open (Lib/_pyio.py): resolve PathLike here so + // _io.FileIO still receives (and preserves on .name) the raw argument + // when called directly. + let file = if file.fast_isinstance(vm.ctx.types.int_type) { + file + } else { + FsPath::try_from_path_like(file, true, vm)?.to_pyobject(vm) + }; + // check file descriptor validity #[cfg(all(unix, feature = "host_env"))] if let Ok(crate::ospath::OsPathOrFd::Fd(fd)) = file.clone().try_into_value(vm) {