Skip to content

Commit

Permalink
Fix mypy and flake8 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rhpvorderman committed Jan 19, 2024
1 parent d4972eb commit a42720a
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/xopen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import subprocess
import tempfile
import time
from subprocess import Popen, PIPE, DEVNULL
from subprocess import Popen, PIPE
from typing import (
Optional,
Union,
Expand Down Expand Up @@ -219,11 +219,9 @@ def __init__(
else:
self.outfile = None
try:
self.process = self._open_process(
mode, compresslevel, threads, self.outfile
)
self.process = self._open_process(mode, compresslevel, threads)
except OSError:
if "r" not in mode:
if self.outfile:
self.outfile.close()
raise
if "r" in mode:
Expand All @@ -249,7 +247,6 @@ def _open_process(
mode: str,
compresslevel: Optional[int],
threads: int,
outfile: BinaryIO,
) -> Popen:
program_args: List[str] = self._program_args[:] # prevent list aliasing
if threads != 0 and self._threads_flag is not None:
Expand All @@ -259,10 +256,10 @@ def _open_process(
program_args += ["-" + str(compresslevel)]

if "r" in mode:
program_args += ["-c", "-d", self._path]
program_args += ["-c", "-d", self._path] # type: ignore
kwargs = dict(stdout=PIPE)
else:
kwargs = dict(stdin=PIPE, stdout=outfile)
kwargs = dict(stdin=PIPE, stdout=self.outfile) # type: ignore

# Setting close_fds to True in the Popen arguments is necessary due to
# <http://bugs.python.org/issue12786>.
Expand Down Expand Up @@ -307,8 +304,8 @@ def close(self) -> None:
return
if "r" not in self._mode:
self._file.close()
retcode = self.process.wait()
self.outfile.close()
self.process.wait()
self.outfile.close() # type: ignore
check_allowed_code_and_message = True
else:
retcode = self.process.poll()
Expand Down

0 comments on commit a42720a

Please sign in to comment.