3434from exec_helpers import proc_enums
3535
3636
37+ _OptionalTimeoutT = typing .Union [int , float , None ]
38+ _OptionalStdinT = typing .Union [bytes , str , bytearray , None ]
39+ _ExitCodeT = typing .Union [int , proc_enums .ExitCodes ]
40+
41+
3742# noinspection PyProtectedMember
38- class _ChRootContext (api ._ChRootContext ): # pylint: disable=protected-access
43+ class _ChRootContext (api ._ChRootContext , typing . AsyncContextManager [ None ] ): # pylint: disable=protected-access
3944 """Async extension for chroot."""
4045
4146 def __init__ (self , conn : "ExecHelper" , path : typing .Optional [typing .Union [str , pathlib .Path ]] = None ) -> None :
@@ -46,7 +51,7 @@ def __init__(self, conn: "ExecHelper", path: typing.Optional[typing.Union[str, p
4651 :param path: chroot path or None for no chroot
4752 :type path: typing.Optional[typing.Union[str, pathlib.Path]]
4853 """
49- super (_ChRootContext , self ).__init__ (conn = conn , path = path )
54+ super ().__init__ (conn = conn , path = path )
5055
5156 async def __aenter__ (self ) -> None :
5257 await self ._conn .__aenter__ ()
@@ -72,7 +77,7 @@ def __init__(self, log_mask_re: typing.Optional[str] = None, *, logger: logging.
7277 all MATCHED groups will be replaced by '<*masked*>'
7378 :type log_mask_re: typing.Optional[str]
7479 """
75- super (ExecHelper , self ).__init__ (logger = logger , log_mask_re = log_mask_re )
80+ super ().__init__ (logger = logger , log_mask_re = log_mask_re )
7681 self .__alock : typing .Optional [asyncio .Lock ] = None
7782
7883 def __enter__ (self ) -> "ExecHelper" : # pylint: disable=useless-super-delegation
@@ -108,11 +113,11 @@ async def _exec_command( # type: ignore
108113 self ,
109114 command : str ,
110115 async_result : api .ExecuteAsyncResult ,
111- timeout : typing . Union [ int , float , None ] ,
116+ timeout : _OptionalTimeoutT ,
112117 * ,
113118 verbose : bool = False ,
114119 log_mask_re : typing .Optional [str ] = None ,
115- stdin : typing . Union [ bytes , str , bytearray , None ] = None ,
120+ stdin : _OptionalStdinT = None ,
116121 ** kwargs : typing .Any ,
117122 ) -> exec_result .ExecResult :
118123 """Get exit status from channel with timeout.
@@ -181,10 +186,10 @@ async def execute( # type: ignore
181186 self ,
182187 command : str ,
183188 verbose : bool = False ,
184- timeout : typing . Union [ int , float , None ] = constants .DEFAULT_TIMEOUT ,
189+ timeout : _OptionalTimeoutT = constants .DEFAULT_TIMEOUT ,
185190 * ,
186191 log_mask_re : typing .Optional [str ] = None ,
187- stdin : typing . Union [ bytes , str , bytearray , None ] = None ,
192+ stdin : _OptionalStdinT = None ,
188193 open_stdout : bool = True ,
189194 open_stderr : bool = True ,
190195 ** kwargs : typing .Any ,
@@ -247,10 +252,10 @@ async def __call__( # type: ignore
247252 self ,
248253 command : str ,
249254 verbose : bool = False ,
250- timeout : typing . Union [ int , float , None ] = constants .DEFAULT_TIMEOUT ,
255+ timeout : _OptionalTimeoutT = constants .DEFAULT_TIMEOUT ,
251256 * ,
252257 log_mask_re : typing .Optional [str ] = None ,
253- stdin : typing . Union [ bytes , str , bytearray , None ] = None ,
258+ stdin : _OptionalStdinT = None ,
254259 open_stdout : bool = True ,
255260 open_stderr : bool = True ,
256261 ** kwargs : typing .Any ,
@@ -295,13 +300,13 @@ async def check_call( # type: ignore
295300 self ,
296301 command : str ,
297302 verbose : bool = False ,
298- timeout : typing . Union [ int , float , None ] = constants .DEFAULT_TIMEOUT ,
303+ timeout : _OptionalTimeoutT = constants .DEFAULT_TIMEOUT ,
299304 error_info : typing .Optional [str ] = None ,
300- expected : typing .Iterable [typing . Union [ int , proc_enums . ExitCodes ] ] = (proc_enums .EXPECTED ,),
305+ expected : typing .Iterable [_ExitCodeT ] = (proc_enums .EXPECTED ,),
301306 raise_on_err : bool = True ,
302307 * ,
303308 log_mask_re : typing .Optional [str ] = None ,
304- stdin : typing . Union [ bytes , str , bytearray , None ] = None ,
309+ stdin : _OptionalStdinT = None ,
305310 open_stdout : bool = True ,
306311 open_stderr : bool = True ,
307312 exception_class : "typing.Type[exceptions.CalledProcessError]" = exceptions .CalledProcessError ,
@@ -341,9 +346,7 @@ async def check_call( # type: ignore
341346
342347 .. versionchanged:: 3.4.0 Expected is not optional, defaults os dependent
343348 """
344- expected_codes : typing .Tuple [typing .Union [int , proc_enums .ExitCodes ], ...] = proc_enums .exit_codes_to_enums (
345- expected
346- )
349+ expected_codes : typing .Sequence [_ExitCodeT ] = proc_enums .exit_codes_to_enums (expected )
347350 result : exec_result .ExecResult = await self .execute (
348351 command ,
349352 verbose = verbose ,
@@ -369,13 +372,13 @@ async def check_stderr( # type: ignore
369372 self ,
370373 command : str ,
371374 verbose : bool = False ,
372- timeout : typing . Union [ int , float , None ] = constants .DEFAULT_TIMEOUT ,
375+ timeout : _OptionalTimeoutT = constants .DEFAULT_TIMEOUT ,
373376 error_info : typing .Optional [str ] = None ,
374377 raise_on_err : bool = True ,
375378 * ,
376- expected : typing .Iterable [typing . Union [ int , proc_enums . ExitCodes ] ] = (proc_enums .EXPECTED ,),
379+ expected : typing .Iterable [_ExitCodeT ] = (proc_enums .EXPECTED ,),
377380 log_mask_re : typing .Optional [str ] = None ,
378- stdin : typing . Union [ bytes , str , bytearray , None ] = None ,
381+ stdin : _OptionalStdinT = None ,
379382 open_stdout : bool = True ,
380383 open_stderr : bool = True ,
381384 exception_class : "typing.Type[exceptions.CalledProcessError]" = exceptions .CalledProcessError ,
0 commit comments