@@ -166,7 +166,7 @@ class _PipedCompressionProgram(io.IOBase):
166
166
167
167
def __init__ ( # noqa: C901
168
168
self ,
169
- filename : Union [ FilePath , BinaryIO ] ,
169
+ filename : FileOrPath ,
170
170
mode = "rb" ,
171
171
compresslevel : Optional [int ] = None ,
172
172
threads : Optional [int ] = None ,
@@ -513,7 +513,7 @@ def _open_zst( # noqa: C901
513
513
cctx = zstandard .ZstdCompressor (level = compresslevel )
514
514
else :
515
515
cctx = None
516
- f = zstandard .open (filename , mode , cctx = cctx )
516
+ f = zstandard .open (filename , mode , cctx = cctx ) # type: ignore
517
517
if mode == "rb" :
518
518
return io .BufferedReader (f )
519
519
elif mode == "wb" :
@@ -669,12 +669,8 @@ def _file_or_path_to_binary_stream(
669
669
raise AssertionError ()
670
670
if file_or_path == "-" :
671
671
return _open_stdin_or_out (binary_mode ), False
672
- try :
673
- filepath = os .fspath (file_or_path )
674
- except TypeError :
675
- pass
676
- else :
677
- return open (filepath , binary_mode ), True # type: ignore
672
+ if isinstance (file_or_path , (str , bytes )) or hasattr (file_or_path , "__fspath__" ):
673
+ return open (os .fspath (file_or_path ), binary_mode ), True # type: ignore
678
674
if isinstance (file_or_path , (io .BufferedReader , io .BufferedWriter )):
679
675
return file_or_path , False
680
676
if isinstance (file_or_path , io .TextIOWrapper ):
@@ -691,7 +687,7 @@ def _file_or_path_to_binary_stream(
691
687
692
688
def filepath_from_path_or_filelike (fileorpath : FileOrPath ):
693
689
try :
694
- return os .fspath (fileorpath )
690
+ return os .fspath (fileorpath ) # type: ignore
695
691
except TypeError :
696
692
pass
697
693
if hasattr (fileorpath , "name" ):
0 commit comments