File tree Expand file tree Collapse file tree 2 files changed +37
-3
lines changed Expand file tree Collapse file tree 2 files changed +37
-3
lines changed Original file line number Diff line number Diff line change 1
1
import io
2
2
import sys
3
- from pathlib import Path
3
+ from pathlib import Path , PurePath
4
4
from unittest .mock import Mock
5
5
6
6
import pytest
@@ -440,3 +440,39 @@ def test_size():
440
440
f = io .BytesIO (b"hello" )
441
441
assert fsspec .utils .file_size (f ) == 5
442
442
assert f .tell () == 0
443
+
444
+
445
+ class _HasFspath :
446
+ def __fspath__ (self ):
447
+ return "foo"
448
+
449
+
450
+ class _HasPathAttr :
451
+ def __init__ (self ):
452
+ self .path = "foo"
453
+
454
+
455
+ @pytest .mark .parametrize (
456
+ "path,expected" ,
457
+ [
458
+ # coerce to string
459
+ ("foo" , "foo" ),
460
+ (Path ("foo" ), "foo" ),
461
+ (PurePath ("foo" ), "foo" ),
462
+ (_HasFspath (), "foo" ),
463
+ (_HasPathAttr (), "foo" ),
464
+ # passthrough
465
+ (b"bytes" , b"bytes" ),
466
+ (None , None ),
467
+ (1 , 1 ),
468
+ (True , True ),
469
+ (o := object (), o ),
470
+ ([], []),
471
+ ((), ()),
472
+ (set (), set ()),
473
+ ],
474
+ )
475
+ def test_stringify_path (path , expected ):
476
+ path = fsspec .utils .stringify_path (path )
477
+
478
+ assert path == expected
Original file line number Diff line number Diff line change @@ -350,8 +350,6 @@ def stringify_path(filepath: str | os.PathLike[str] | pathlib.Path) -> str:
350
350
return filepath
351
351
elif hasattr (filepath , "__fspath__" ):
352
352
return filepath .__fspath__ ()
353
- elif isinstance (filepath , pathlib .Path ):
354
- return str (filepath )
355
353
elif hasattr (filepath , "path" ):
356
354
return filepath .path
357
355
else :
You can’t perform that action at this time.
0 commit comments