Skip to content

Commit 2dd88ce

Browse files
committed
Fix mypy errors
1 parent 6d140d0 commit 2dd88ce

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/xopen/__init__.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class _PipedCompressionProgram(io.IOBase):
166166

167167
def __init__( # noqa: C901
168168
self,
169-
filename: Union[FilePath, BinaryIO],
169+
filename: FileOrPath,
170170
mode="rb",
171171
compresslevel: Optional[int] = None,
172172
threads: Optional[int] = None,
@@ -513,7 +513,7 @@ def _open_zst( # noqa: C901
513513
cctx = zstandard.ZstdCompressor(level=compresslevel)
514514
else:
515515
cctx = None
516-
f = zstandard.open(filename, mode, cctx=cctx)
516+
f = zstandard.open(filename, mode, cctx=cctx) # type: ignore
517517
if mode == "rb":
518518
return io.BufferedReader(f)
519519
elif mode == "wb":
@@ -669,12 +669,8 @@ def _file_or_path_to_binary_stream(
669669
raise AssertionError()
670670
if file_or_path == "-":
671671
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
678674
if isinstance(file_or_path, (io.BufferedReader, io.BufferedWriter)):
679675
return file_or_path, False
680676
if isinstance(file_or_path, io.TextIOWrapper):
@@ -691,7 +687,7 @@ def _file_or_path_to_binary_stream(
691687

692688
def filepath_from_path_or_filelike(fileorpath: FileOrPath):
693689
try:
694-
return os.fspath(fileorpath)
690+
return os.fspath(fileorpath) # type: ignore
695691
except TypeError:
696692
pass
697693
if hasattr(fileorpath, "name"):

0 commit comments

Comments
 (0)