Skip to content

Commit 69aa808

Browse files
committed
Fix copy-paste of types: import from first definition place
1 parent bb7f518 commit 69aa808

File tree

11 files changed

+159
-158
lines changed

11 files changed

+159
-158
lines changed

exec_helpers/_ssh_client_base.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,15 @@
4545
from exec_helpers import exec_result
4646
from exec_helpers import proc_enums
4747
from exec_helpers import ssh_auth
48+
from exec_helpers.api import CalledProcessErrorSubClassT
49+
from exec_helpers.api import OptionalStdinT
50+
from exec_helpers.api import OptionalTimeoutT
51+
from exec_helpers.proc_enums import ExitCodeT
4852

4953
# Local Implementation
5054
from ._ssh_helpers import HostsSSHConfigs
5155
from ._ssh_helpers import SSHConfig
5256

53-
5457
_OptionalSSHAuthMapT = typing.Optional[typing.Union[typing.Dict[str, ssh_auth.SSHAuth], ssh_auth.SSHAuthMapping]]
5558
_OptionalSSHConfigArgT = typing.Union[
5659
str,
@@ -61,9 +64,6 @@
6164
]
6265
_SSHConnChainT = typing.List[typing.Tuple[SSHConfig, ssh_auth.SSHAuth]]
6366
_OptSSHAuthT = typing.Optional[ssh_auth.SSHAuth]
64-
_OptTimeoutT = typing.Union[int, float, None]
65-
_OptStdinT = typing.Union[bytes, str, bytearray, None]
66-
_ExitCodeT = typing.Union[int, proc_enums.ExitCodes]
6767

6868

6969
class RetryOnExceptions(tenacity.retry_if_exception): # type: ignore
@@ -581,6 +581,7 @@ def keepalive_mode(self) -> int:
581581
warnings.warn("keepalive_mode was moved to keepalive_period as time based parameter", DeprecationWarning)
582582
return self.keepalive_period
583583

584+
# noinspection PyDeprecation
584585
@keepalive_mode.setter
585586
def keepalive_mode(self, period: typing.Union[int, bool]) -> None:
586587
"""Keepalive period change for connection object.
@@ -641,7 +642,7 @@ def _execute_async( # pylint: disable=arguments-differ
641642
self,
642643
command: str,
643644
*,
644-
stdin: _OptStdinT = None,
645+
stdin: OptionalStdinT = None,
645646
open_stdout: bool = True,
646647
open_stderr: bool = True,
647648
chroot_path: typing.Optional[str] = None,
@@ -732,11 +733,11 @@ def _exec_command( # type: ignore
732733
self,
733734
command: str,
734735
async_result: SshExecuteAsyncResult,
735-
timeout: _OptTimeoutT,
736+
timeout: OptionalTimeoutT,
736737
*,
737738
verbose: bool = False,
738739
log_mask_re: typing.Optional[str] = None,
739-
stdin: _OptStdinT = None,
740+
stdin: OptionalStdinT = None,
740741
**kwargs: typing.Any,
741742
) -> exec_result.ExecResult:
742743
"""Get exit status from channel with timeout.
@@ -813,10 +814,10 @@ def execute( # pylint: disable=arguments-differ
813814
self,
814815
command: str,
815816
verbose: bool = False,
816-
timeout: _OptTimeoutT = constants.DEFAULT_TIMEOUT,
817+
timeout: OptionalTimeoutT = constants.DEFAULT_TIMEOUT,
817818
*,
818819
log_mask_re: typing.Optional[str] = None,
819-
stdin: _OptStdinT = None,
820+
stdin: OptionalStdinT = None,
820821
open_stdout: bool = True,
821822
open_stderr: bool = True,
822823
get_pty: bool = False,
@@ -874,10 +875,10 @@ def __call__(
874875
self,
875876
command: str,
876877
verbose: bool = False,
877-
timeout: _OptTimeoutT = constants.DEFAULT_TIMEOUT,
878+
timeout: OptionalTimeoutT = constants.DEFAULT_TIMEOUT,
878879
*,
879880
log_mask_re: typing.Optional[str] = None,
880-
stdin: _OptStdinT = None,
881+
stdin: OptionalStdinT = None,
881882
open_stdout: bool = True,
882883
open_stderr: bool = True,
883884
get_pty: bool = False,
@@ -935,19 +936,19 @@ def check_call( # pylint: disable=arguments-differ
935936
self,
936937
command: str,
937938
verbose: bool = False,
938-
timeout: _OptTimeoutT = constants.DEFAULT_TIMEOUT,
939+
timeout: OptionalTimeoutT = constants.DEFAULT_TIMEOUT,
939940
error_info: typing.Optional[str] = None,
940-
expected: typing.Iterable[_ExitCodeT] = (proc_enums.EXPECTED,),
941+
expected: typing.Iterable[ExitCodeT] = (proc_enums.EXPECTED,),
941942
raise_on_err: bool = True,
942943
*,
943944
log_mask_re: typing.Optional[str] = None,
944-
stdin: _OptStdinT = None,
945+
stdin: OptionalStdinT = None,
945946
open_stdout: bool = True,
946947
open_stderr: bool = True,
947948
get_pty: bool = False,
948949
width: int = 80,
949950
height: int = 24,
950-
exception_class: "typing.Type[exceptions.CalledProcessError]" = exceptions.CalledProcessError,
951+
exception_class: CalledProcessErrorSubClassT = exceptions.CalledProcessError,
951952
**kwargs: typing.Any,
952953
) -> exec_result.ExecResult:
953954
"""Execute command and check for return code.
@@ -1014,19 +1015,19 @@ def check_stderr( # pylint: disable=arguments-differ
10141015
self,
10151016
command: str,
10161017
verbose: bool = False,
1017-
timeout: _OptTimeoutT = constants.DEFAULT_TIMEOUT,
1018+
timeout: OptionalTimeoutT = constants.DEFAULT_TIMEOUT,
10181019
error_info: typing.Optional[str] = None,
10191020
raise_on_err: bool = True,
10201021
*,
1021-
expected: typing.Iterable[_ExitCodeT] = (proc_enums.EXPECTED,),
1022+
expected: typing.Iterable[ExitCodeT] = (proc_enums.EXPECTED,),
10221023
log_mask_re: typing.Optional[str] = None,
1023-
stdin: _OptStdinT = None,
1024+
stdin: OptionalStdinT = None,
10241025
open_stdout: bool = True,
10251026
open_stderr: bool = True,
10261027
get_pty: bool = False,
10271028
width: int = 80,
10281029
height: int = 24,
1029-
exception_class: "typing.Type[exceptions.CalledProcessError]" = exceptions.CalledProcessError,
1030+
exception_class: CalledProcessErrorSubClassT = exceptions.CalledProcessError,
10301031
**kwargs: typing.Any,
10311032
) -> exec_result.ExecResult:
10321033
"""Execute command expecting return code 0 and empty STDERR.
@@ -1188,8 +1189,8 @@ def execute_through_host(
11881189
port: typing.Optional[int] = None,
11891190
target_port: typing.Optional[int] = None,
11901191
verbose: bool = False,
1191-
timeout: _OptTimeoutT = constants.DEFAULT_TIMEOUT,
1192-
stdin: _OptStdinT = None,
1192+
timeout: OptionalTimeoutT = constants.DEFAULT_TIMEOUT,
1193+
stdin: OptionalStdinT = None,
11931194
open_stdout: bool = True,
11941195
open_stderr: bool = True,
11951196
log_mask_re: typing.Optional[str] = None,
@@ -1270,11 +1271,11 @@ def execute_together(
12701271
cls,
12711272
remotes: typing.Iterable["SSHClientBase"],
12721273
command: str,
1273-
timeout: _OptTimeoutT = constants.DEFAULT_TIMEOUT,
1274-
expected: typing.Iterable[_ExitCodeT] = (proc_enums.EXPECTED,),
1274+
timeout: OptionalTimeoutT = constants.DEFAULT_TIMEOUT,
1275+
expected: typing.Iterable[ExitCodeT] = (proc_enums.EXPECTED,),
12751276
raise_on_err: bool = True,
12761277
*,
1277-
stdin: _OptStdinT = None,
1278+
stdin: OptionalStdinT = None,
12781279
open_stdout: bool = True,
12791280
open_stderr: bool = True,
12801281
verbose: bool = False,
@@ -1353,7 +1354,7 @@ def get_result(remote: "SSHClientBase") -> exec_result.ExecResult:
13531354
async_result.interface.close()
13541355
return res
13551356

1356-
prep_expected: typing.Sequence[_ExitCodeT] = proc_enums.exit_codes_to_enums(expected)
1357+
prep_expected: typing.Sequence[ExitCodeT] = proc_enums.exit_codes_to_enums(expected)
13571358
log_level: int = logging.INFO if verbose else logging.DEBUG
13581359

13591360
futures: typing.Dict["SSHClientBase", "concurrent.futures.Future[exec_result.ExecResult]"] = {

exec_helpers/_subprocess_helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def safe_stop(proc: psutil.Process, kill: bool = False) -> None:
4949

5050
parent = psutil.Process(pid)
5151
children: typing.List[psutil.Process] = parent.children(recursive=True)
52-
for child in children: # type: psutil.Process
52+
child: psutil.Process
53+
for child in children:
5354
safe_stop(child) # SIGTERM to allow cleanup
5455
_, alive = psutil.wait_procs(children, timeout=1)
5556
for child in alive:

exec_helpers/api.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@
1919
.. versionchanged:: 1.3.5 make API public to use as interface
2020
"""
2121

22-
__all__ = ("ExecHelper", "ExecuteAsyncResult", "mask_command")
22+
__all__ = (
23+
"ExecHelper",
24+
"ExecuteAsyncResult",
25+
"mask_command",
26+
"CalledProcessErrorSubClassT",
27+
"OptionalStdinT",
28+
"OptionalTimeoutT",
29+
)
2330

2431
# Standard Library
2532
import abc
@@ -36,6 +43,7 @@
3643
from exec_helpers import exceptions
3744
from exec_helpers import exec_result
3845
from exec_helpers import proc_enums
46+
from exec_helpers.proc_enums import ExitCodeT
3947

4048
ExecuteAsyncResult = typing.NamedTuple(
4149
"ExecuteAsyncResult",
@@ -47,10 +55,9 @@
4755
("started", datetime.datetime),
4856
],
4957
)
50-
_OptionalTimeoutT = typing.Union[int, float, None]
51-
_OptionalStdinT = typing.Union[bytes, str, bytearray, None]
52-
_ExitCodeT = typing.Union[int, proc_enums.ExitCodes]
53-
_CalledProcessErrorSubClass = typing.Type[exceptions.CalledProcessError]
58+
OptionalTimeoutT = typing.Union[int, float, None]
59+
OptionalStdinT = typing.Union[bytes, str, bytearray, None]
60+
CalledProcessErrorSubClassT = typing.Type[exceptions.CalledProcessError]
5461

5562

5663
# noinspection PyProtectedMember
@@ -249,7 +256,7 @@ def _execute_async(
249256
self,
250257
command: str,
251258
*,
252-
stdin: _OptionalStdinT = None,
259+
stdin: OptionalStdinT = None,
253260
open_stdout: bool = True,
254261
open_stderr: bool = True,
255262
chroot_path: typing.Optional[str] = None,
@@ -293,11 +300,11 @@ def _exec_command(
293300
self,
294301
command: str,
295302
async_result: ExecuteAsyncResult,
296-
timeout: _OptionalTimeoutT,
303+
timeout: OptionalTimeoutT,
297304
*,
298305
verbose: bool = False,
299306
log_mask_re: typing.Optional[str] = None,
300-
stdin: _OptionalStdinT = None,
307+
stdin: OptionalStdinT = None,
301308
**kwargs: typing.Any,
302309
) -> exec_result.ExecResult:
303310
"""Get exit status from channel with timeout.
@@ -343,10 +350,10 @@ def execute(
343350
self,
344351
command: str,
345352
verbose: bool = False,
346-
timeout: _OptionalTimeoutT = constants.DEFAULT_TIMEOUT,
353+
timeout: OptionalTimeoutT = constants.DEFAULT_TIMEOUT,
347354
*,
348355
log_mask_re: typing.Optional[str] = None,
349-
stdin: _OptionalStdinT = None,
356+
stdin: OptionalStdinT = None,
350357
open_stdout: bool = True,
351358
open_stderr: bool = True,
352359
**kwargs: typing.Any,
@@ -405,10 +412,10 @@ def __call__(
405412
self,
406413
command: str,
407414
verbose: bool = False,
408-
timeout: _OptionalTimeoutT = constants.DEFAULT_TIMEOUT,
415+
timeout: OptionalTimeoutT = constants.DEFAULT_TIMEOUT,
409416
*,
410417
log_mask_re: typing.Optional[str] = None,
411-
stdin: _OptionalStdinT = None,
418+
stdin: OptionalStdinT = None,
412419
open_stdout: bool = True,
413420
open_stderr: bool = True,
414421
**kwargs: typing.Any,
@@ -453,16 +460,16 @@ def check_call(
453460
self,
454461
command: str,
455462
verbose: bool = False,
456-
timeout: _OptionalTimeoutT = constants.DEFAULT_TIMEOUT,
463+
timeout: OptionalTimeoutT = constants.DEFAULT_TIMEOUT,
457464
error_info: typing.Optional[str] = None,
458-
expected: typing.Iterable[_ExitCodeT] = (proc_enums.EXPECTED,),
465+
expected: typing.Iterable[ExitCodeT] = (proc_enums.EXPECTED,),
459466
raise_on_err: bool = True,
460467
*,
461468
log_mask_re: typing.Optional[str] = None,
462-
stdin: _OptionalStdinT = None,
469+
stdin: OptionalStdinT = None,
463470
open_stdout: bool = True,
464471
open_stderr: bool = True,
465-
exception_class: _CalledProcessErrorSubClass = exceptions.CalledProcessError,
472+
exception_class: CalledProcessErrorSubClassT = exceptions.CalledProcessError,
466473
**kwargs: typing.Any,
467474
) -> exec_result.ExecResult:
468475
"""Execute command and check for return code.
@@ -501,7 +508,7 @@ def check_call(
501508
.. versionchanged:: 3.2.0 Exception class can be substituted
502509
.. versionchanged:: 3.4.0 Expected is not optional, defaults os dependent
503510
"""
504-
expected_codes: typing.Sequence[_ExitCodeT] = proc_enums.exit_codes_to_enums(expected)
511+
expected_codes: typing.Sequence[ExitCodeT] = proc_enums.exit_codes_to_enums(expected)
505512
result: exec_result.ExecResult = self.execute(
506513
command,
507514
verbose=verbose,
@@ -527,16 +534,16 @@ def check_stderr(
527534
self,
528535
command: str,
529536
verbose: bool = False,
530-
timeout: _OptionalTimeoutT = constants.DEFAULT_TIMEOUT,
537+
timeout: OptionalTimeoutT = constants.DEFAULT_TIMEOUT,
531538
error_info: typing.Optional[str] = None,
532539
raise_on_err: bool = True,
533540
*,
534-
expected: typing.Iterable[_ExitCodeT] = (proc_enums.EXPECTED,),
541+
expected: typing.Iterable[ExitCodeT] = (proc_enums.EXPECTED,),
535542
log_mask_re: typing.Optional[str] = None,
536-
stdin: _OptionalStdinT = None,
543+
stdin: OptionalStdinT = None,
537544
open_stdout: bool = True,
538545
open_stderr: bool = True,
539-
exception_class: _CalledProcessErrorSubClass = exceptions.CalledProcessError,
546+
exception_class: CalledProcessErrorSubClassT = exceptions.CalledProcessError,
540547
**kwargs: typing.Any,
541548
) -> exec_result.ExecResult:
542549
"""Execute command expecting return code 0 and empty STDERR.
@@ -602,8 +609,8 @@ def _handle_stderr(
602609
result: exec_result.ExecResult,
603610
error_info: typing.Optional[str],
604611
raise_on_err: bool,
605-
expected: typing.Iterable[_ExitCodeT],
606-
exception_class: _CalledProcessErrorSubClass,
612+
expected: typing.Iterable[ExitCodeT],
613+
exception_class: CalledProcessErrorSubClassT,
607614
) -> exec_result.ExecResult:
608615
"""Internal check_stderr logic (synchronous)."""
609616
append: str = error_info + "\n" if error_info else ""

0 commit comments

Comments
 (0)