os: Fix error message of fspath

This commit is contained in:
Dean Li
2021-06-13 13:48:39 +08:00
parent d458669e8c
commit 62f49ed4de
2 changed files with 2 additions and 4 deletions

View File

@@ -3681,8 +3681,6 @@ class PathTConverterTests(unittest.TestCase):
'os.PathLike'):
fn(fd, *extra_args)
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_path_t_converter_and_custom_class(self):
msg = r'__fspath__\(\) to return str or bytes, not %s'
with self.assertRaisesRegex(TypeError, msg % r'int'):

View File

@@ -158,14 +158,14 @@ fn fspath(obj: PyObjectRef, check_for_nul: bool, vm: &VirtualMachine) -> PyResul
}
let method = vm.get_method_or_type_error(obj.clone(), "__fspath__", || {
format!(
"expected str, bytes or os.PathLike object, not '{}'",
"expected str, bytes or os.PathLike object, not {}",
obj.class().name
)
})?;
let result = vm.invoke(&method, ())?;
match1(&result)?.ok_or_else(|| {
vm.new_type_error(format!(
"expected {}.__fspath__() to return str or bytes, not '{}'",
"expected {}.__fspath__() to return str or bytes, not {}",
obj.class().name,
result.class().name,
))