File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -307,6 +307,13 @@ def test_format_file_path_for_error_falls_back_for_non_string_values():
307307 assert format_file_path_for_error (object ()) == "<provided path>"
308308
309309
310+ def test_format_file_path_for_error_falls_back_for_string_subclass_values ():
311+ class _PathString (str ):
312+ pass
313+
314+ assert format_file_path_for_error (_PathString ("/tmp/value" )) == "<provided path>"
315+
316+
310317def test_format_file_path_for_error_falls_back_for_fspath_failures ():
311318 class _BrokenPathLike :
312319 def __fspath__ (self ) -> str :
@@ -323,6 +330,17 @@ def __fspath__(self) -> str:
323330 assert format_file_path_for_error (_PathLike ()) == "/tmp/path-value"
324331
325332
333+ def test_format_file_path_for_error_falls_back_for_pathlike_string_subclass_values ():
334+ class _PathLike :
335+ class _PathString (str ):
336+ pass
337+
338+ def __fspath__ (self ) -> str :
339+ return self ._PathString ("/tmp/path-value" )
340+
341+ assert format_file_path_for_error (_PathLike ()) == "<provided path>"
342+
343+
326344def test_build_open_file_error_message_uses_prefix_and_sanitized_path ():
327345 message = build_open_file_error_message (
328346 "bad\t path.txt" ,
You can’t perform that action at this time.
0 commit comments