@@ -357,11 +357,11 @@ class AutoInterrupt(object):
357
357
358
358
__slots__ = ("proc" , "args" )
359
359
360
- def __init__ (self , proc , args ) :
360
+ def __init__ (self , proc : Union [ None , subprocess . Popen ], args : Any ) -> None :
361
361
self .proc = proc
362
362
self .args = args
363
363
364
- def __del__ (self ):
364
+ def __del__ (self ) -> None :
365
365
if self .proc is None :
366
366
return
367
367
@@ -377,13 +377,13 @@ def __del__(self):
377
377
# did the process finish already so we have a return code ?
378
378
try :
379
379
if proc .poll () is not None :
380
- return
380
+ return None
381
381
except OSError as ex :
382
382
log .info ("Ignored error after process had died: %r" , ex )
383
383
384
384
# can be that nothing really exists anymore ...
385
385
if os is None or getattr (os , 'kill' , None ) is None :
386
- return
386
+ return None
387
387
388
388
# try to kill it
389
389
try :
@@ -400,10 +400,11 @@ def __del__(self):
400
400
call (("TASKKILL /F /T /PID %s 2>nul 1>nul" % str (proc .pid )), shell = True )
401
401
# END exception handling
402
402
403
- def __getattr__ (self , attr ) :
403
+ def __getattr__ (self , attr : str ) -> Any :
404
404
return getattr (self .proc , attr )
405
405
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 :
407
408
"""Wait for the process and return its status code.
408
409
409
410
: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
413
414
stderr = b''
414
415
stderr = force_bytes (data = stderr , encoding = 'utf-8' )
415
416
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 ()
423
419
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 )
428
430
# END status handling
429
431
return status
432
+
430
433
# END auto interrupt
431
434
432
435
class CatFileContentStream (object ):
0 commit comments