1616from pathlib import Path
1717from select import EPOLLHUP , EPOLLIN , epoll
1818from shutil import which
19+ from types import TracebackType
1920from typing import Any , override
2021
2122from .exceptions import RequirementError , SysCallError
@@ -170,7 +171,7 @@ def __str__(self) -> str:
170171 def __enter__ (self ) -> 'SysCommandWorker' :
171172 return self
172173
173- def __exit__ (self , * args : str ) -> None :
174+ def __exit__ (self , exc_type : type [ BaseException ] | None , exc_value : BaseException | None , traceback : TracebackType | None ) -> None :
174175 # b''.join(sys_command('sync')) # No need to, since the underlying fs() object will call sync.
175176 # TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager
176177
@@ -186,8 +187,8 @@ def __exit__(self, *args: str) -> None:
186187 sys .stdout .write ('\n ' )
187188 sys .stdout .flush ()
188189
189- if len ( args ) >= 2 and args [ 1 ] :
190- debug (args [ 1 ] )
190+ if exc_type is not None :
191+ debug (str ( exc_value ) )
191192
192193 if self .exit_code != 0 :
193194 raise SysCallError (
@@ -327,12 +328,12 @@ def __init__(
327328 def __enter__ (self ) -> SysCommandWorker | None :
328329 return self .session
329330
330- def __exit__ (self , * args : str , ** kwargs : dict [ str , Any ] ) -> None :
331+ def __exit__ (self , exc_type : type [ BaseException ] | None , exc_value : BaseException | None , traceback : TracebackType | None ) -> None :
331332 # b''.join(sys_command('sync')) # No need to, since the underlying fs() object will call sync.
332333 # TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager
333334
334- if len ( args ) >= 2 and args [ 1 ] :
335- error (args [ 1 ] )
335+ if exc_type is not None :
336+ error (str ( exc_value ) )
336337
337338 def __iter__ (self , * args : list [Any ], ** kwargs : dict [str , Any ]) -> Iterator [bytes ]:
338339 if self .session :
0 commit comments