Skip to content

Commit

Permalink
make flake8 and mypy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
sroet authored and Byron committed Sep 18, 2021
1 parent cd2d538 commit 144817a
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions git/cmd.py
Expand Up @@ -154,14 +154,22 @@ def pump_stream(cmdline: List[str], name: str, stream: Union[BinaryIO, TextIO],
for t in threads:
t.join(timeout=kill_after_timeout)
if t.is_alive():
if hasattr(process, 'proc'): # Assume it is a Git.AutoInterrupt:
if isinstance(process, Git.AutoInterrupt):
process._terminate()
else: # Don't want to deal with the other case
raise RuntimeError(f"Thread join() timed out in cmd.handle_process_output()."
" kill_after_timeout={kill_after_timeout} seconds")
raise RuntimeError("Thread join() timed out in cmd.handle_process_output()."
f" kill_after_timeout={kill_after_timeout} seconds")
if stderr_handler:
stderr_handler("error: process killed because it timed out."
f" kill_after_timeout={kill_after_timeout} seconds")
error_str: Union[str, bytes] = (
"error: process killed because it timed out."
f" kill_after_timeout={kill_after_timeout} seconds")
if not decode_streams and isinstance(p_stderr, BinaryIO):
# Assume stderr_handler needs binary input
error_str = cast(str, error_str)
error_str = error_str.encode()
# We ignore typing on the next line because mypy does not like
# the way we infered that stderr takes str of bytes
stderr_handler(error_str) # type: ignore

if finalizer:
return finalizer(process)
Expand Down Expand Up @@ -404,7 +412,7 @@ class AutoInterrupt(object):
def __init__(self, proc: Union[None, subprocess.Popen], args: Any) -> None:
self.proc = proc
self.args = args
self.status = None
self.status: Union[int, None] = None

def _terminate(self) -> None:
"""Terminate the underlying process"""
Expand Down Expand Up @@ -447,8 +455,6 @@ def _terminate(self) -> None:
call(("TASKKILL /F /T /PID %s 2>nul 1>nul" % str(proc.pid)), shell=True)
# END exception handling



def __del__(self) -> None:
self._terminate()

Expand All @@ -465,11 +471,11 @@ def wait(self, stderr: Union[None, str, bytes] = b'') -> int:
if stderr is None:
stderr_b = b''
stderr_b = force_bytes(data=stderr, encoding='utf-8')

status: Union[int, None]
if self.proc is not None:
status = self.proc.wait()
p_stderr = self.proc.stderr
else: #Assume the underlying proc was killed earlier or never existed
else: # Assume the underlying proc was killed earlier or never existed
status = self.status
p_stderr = None

Expand Down

0 comments on commit 144817a

Please sign in to comment.