@@ -357,11 +357,11 @@ class AutoInterrupt(object):
357357
358358 __slots__ = ("proc", "args")
359359
360- def __init__(self, proc, args) :
360+ def __init__(self, proc: Union[None, subprocess.Popen], args: Any) -> None :
361361 self.proc = proc
362362 self.args = args
363363
364- def __del__(self):
364+ def __del__(self) -> None :
365365 if self.proc is None:
366366 return
367367
@@ -377,13 +377,13 @@ def __del__(self):
377377 # did the process finish already so we have a return code ?
378378 try:
379379 if proc.poll() is not None:
380- return
380+ return None
381381 except OSError as ex:
382382 log.info("Ignored error after process had died: %r", ex)
383383
384384 # can be that nothing really exists anymore ...
385385 if os is None or getattr(os, 'kill', None) is None:
386- return
386+ return None
387387
388388 # try to kill it
389389 try:
@@ -400,10 +400,11 @@ def __del__(self):
400400 call(("TASKKILL /F /T /PID %s 2>nul 1>nul" % str(proc.pid)), shell=True)
401401 # END exception handling
402402
403- def __getattr__(self, attr) :
403+ def __getattr__(self, attr: str) -> Any :
404404 return getattr(self.proc, attr)
405405
406- def wait(self, stderr=b''): # TODO: Bad choice to mimic `proc.wait()` but with different args.
406+ # TODO: Bad choice to mimic `proc.wait()` but with different args.
407+ def wait(self, stderr: Union[None, bytes] = b'') -> int:
407408 """Wait for the process and return its status code.
408409
409410 :param stderr: Previously read value of stderr, in case stderr is already closed.
@@ -413,20 +414,22 @@ def wait(self, stderr=b''): # TODO: Bad choice to mimic `proc.wait()` but with
413414 stderr = b''
414415 stderr = force_bytes(data=stderr, encoding='utf-8')
415416
416- status = self.proc.wait()
417-
418- def read_all_from_possibly_closed_stream(stream):
419- try:
420- return stderr + force_bytes(stream.read())
421- except ValueError:
422- return stderr or b''
417+ if self.proc is not None:
418+ status = self.proc.wait()
423419
424- if status != 0:
425- errstr = read_all_from_possibly_closed_stream(self.proc.stderr)
426- log.debug('AutoInterrupt wait stderr: %r' % (errstr,))
427- raise GitCommandError(remove_password_if_present(self.args), status, errstr)
420+ def read_all_from_possibly_closed_stream(stream):
421+ try:
422+ return stderr + force_bytes(stream.read())
423+ except ValueError:
424+ return stderr or b''
425+
426+ if status != 0:
427+ errstr = read_all_from_possibly_closed_stream(self.proc.stderr)
428+ log.debug('AutoInterrupt wait stderr: %r' % (errstr,))
429+ raise GitCommandError(remove_password_if_present(self.args), status, errstr)
428430 # END status handling
429431 return status
432+
430433 # END auto interrupt
431434
432435 class CatFileContentStream(object):
0 commit comments