Skip to content

Commit a0c31aa

Browse files
authored
Declare more types (add local mypy target), block pylint>=2 (#54)
1 parent eccf075 commit a0c31aa

File tree

5 files changed

+44
-25
lines changed

5 files changed

+44
-25
lines changed

exec_helpers/_api.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ExecHelper:
1515
@property
1616
def lock(self) -> threading.RLock: ...
1717

18-
def __enter__(self): ...
18+
def __enter__(self) -> ExecHelper: ...
1919

2020
def __exit__(self, exc_type: typing.Any, exc_val: typing.Any, exc_tb: typing.Any) -> None: ...
2121

@@ -29,7 +29,7 @@ class ExecHelper:
2929
open_stderr: bool=...,
3030
verbose: bool=...,
3131
log_mask_re: typing.Optional[str]=...,
32-
**kwargs
32+
**kwargs: typing.Dict
3333
) -> typing.Tuple[typing.Any, typing.Any, typing.Any, typing.Any,]: ...
3434

3535
def _exec_command(
@@ -41,15 +41,15 @@ class ExecHelper:
4141
timeout: typing.Union[int, None],
4242
verbose: bool=...,
4343
log_mask_re: typing.Optional[str]=...,
44-
**kwargs
44+
**kwargs: typing.Dict
4545
) -> exec_result.ExecResult: ...
4646

4747
def execute(
4848
self,
4949
command: str,
5050
verbose: bool=...,
5151
timeout: typing.Union[int, None]=...,
52-
**kwargs
52+
**kwargs: typing.Type
5353
) -> exec_result.ExecResult: ...
5454

5555
def check_call(
@@ -60,7 +60,7 @@ class ExecHelper:
6060
error_info: typing.Optional[str]=...,
6161
expected: typing.Optional[typing.Iterable[typing.Union[int, proc_enums.ExitCodes]]]=...,
6262
raise_on_err: bool=...,
63-
**kwargs
63+
**kwargs: typing.Type
6464
) -> exec_result.ExecResult: ...
6565

6666
def check_stderr(
@@ -70,5 +70,5 @@ class ExecHelper:
7070
timeout: typing.Union[int, None]=...,
7171
error_info: typing.Optional[str]=...,
7272
raise_on_err: bool=...,
73-
**kwargs
73+
**kwargs: typing.Dict
7474
) -> exec_result.ExecResult: ...

exec_helpers/_ssh_client_base.pyi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ from exec_helpers import exec_result, ssh_auth, _api
88

99
class _MemorizedSSH(type):
1010
@classmethod
11-
def __prepare__(mcs, name: str, bases: typing.Iterable[typing.Type], **kwargs) -> collections.OrderedDict: ...
11+
def __prepare__(mcs: typing.Type, name: str, bases: typing.Iterable[typing.Type], **kwargs: typing.Dict) -> collections.OrderedDict: ...
1212

1313
def __call__( # type: ignore
14-
cls,
14+
cls: typing.Type[SSHClientBase],
1515
host: str,
1616
port: int=...,
1717
username: typing.Optional[str]=...,
@@ -22,14 +22,14 @@ class _MemorizedSSH(type):
2222
) -> SSHClientBase: ...
2323

2424
@classmethod
25-
def clear_cache(mcs) -> None: ...
25+
def clear_cache(mcs: typing.Type[SSHClientBase]) -> None: ... # type: ignore
2626

2727
@classmethod
28-
def close_connections(mcs) -> None: ...
28+
def close_connections(mcs: typing.Type[SSHClientBase]) -> None: ... # type: ignore
2929

3030

3131
class SSHClientBase(_api.ExecHelper, metaclass=_MemorizedSSH):
32-
def __hash__(self): ...
32+
def __hash__(self) -> int: ...
3333

3434
def __init__(
3535
self,
@@ -100,7 +100,7 @@ class SSHClientBase(_api.ExecHelper, metaclass=_MemorizedSSH):
100100
open_stderr: bool=...,
101101
verbose: bool=...,
102102
log_mask_re: typing.Optional[str]=...,
103-
**kwargs
103+
**kwargs: typing.Dict
104104
) -> typing.Tuple[paramiko.Channel, paramiko.ChannelFile, typing.Optional[paramiko.ChannelFile], typing.Optional[paramiko.ChannelFile]]: ...
105105

106106
def _exec_command(
@@ -112,7 +112,7 @@ class SSHClientBase(_api.ExecHelper, metaclass=_MemorizedSSH):
112112
timeout: typing.Union[int, None],
113113
verbose: bool=...,
114114
log_mask_re: typing.Optional[str]=...,
115-
**kwargs
115+
**kwargs: typing.Dict
116116
) -> exec_result.ExecResult: ...
117117

118118
def execute_through_host(
@@ -124,7 +124,7 @@ class SSHClientBase(_api.ExecHelper, metaclass=_MemorizedSSH):
124124
verbose: bool=...,
125125
timeout: typing.Union[int, None]=...,
126126
get_pty: bool=...,
127-
**kwargs
127+
**kwargs: typing.Dict
128128
) -> exec_result.ExecResult: ...
129129

130130
@classmethod
@@ -135,7 +135,7 @@ class SSHClientBase(_api.ExecHelper, metaclass=_MemorizedSSH):
135135
timeout: typing.Union[int, None]=...,
136136
expected: typing.Optional[typing.Iterable[int]]=...,
137137
raise_on_err: bool=...,
138-
**kwargs
138+
**kwargs: typing.Dict
139139
) -> typing.Dict[typing.Tuple[str, int], exec_result.ExecResult]: ...
140140

141141
def open(self, path: str, mode: str = ...) -> paramiko.SFTPFile: ...

exec_helpers/proc_enums.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ class SigNum(enum.IntEnum):
7272
SIGPWR = 30 # Power failure restart (System V).
7373
SIGSYS = 31 # Bad system call.
7474

75-
def __str__(self): # pragma: no cover
75+
def __str__(self): # type: () -> str
7676
"""Representation for logs."""
77-
return "{name}<{value:d}(0x{value:02X})>".format(
77+
return "{name}<{value:d}(0x{value:02X})>".format( # pragma: no cover
7878
name=self.name,
7979
value=self.value
8080
)
@@ -150,7 +150,7 @@ class ExitCodes(digit_type, enum.Enum):
150150
EX_SIGPWR = 128 + SigNum.SIGPWR
151151
EX_SIGSYS = 128 + SigNum.SIGSYS
152152

153-
def __str__(self):
153+
def __str__(self): # type: () -> str
154154
"""Representation for logs."""
155155
return "{name}<{value:d}(0x{value:02X})>".format(
156156
name=self.name,

exec_helpers/subprocess_runner.pyi

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ class SingletonMeta(type):
1616
_instances: typing.Dict[typing.Type, typing.Any] = ...
1717
_lock: threading.RLock = ...
1818

19-
def __call__(cls, *args, **kwargs): ...
19+
def __call__(cls: typing.Type, *args: typing.Tuple, **kwargs: typing.Dict) -> typing.Any: ...
2020

2121
@classmethod
22-
def __prepare__(mcs, name: str, bases: typing.Iterable[typing.Type], **kwargs) -> collections.OrderedDict: ...
22+
def __prepare__(mcs: typing.Type, name: str, bases: typing.Iterable[typing.Type], **kwargs: typing.Dict) -> collections.OrderedDict: ...
2323

2424

2525
def set_nonblocking_pipe(pipe: typing.Any) -> None: ...
@@ -40,16 +40,29 @@ class Subprocess(_api.ExecHelper, metaclass=SingletonMeta):
4040
timeout: typing.Union[int, None],
4141
verbose: bool=...,
4242
log_mask_re: typing.Optional[str]=...,
43-
**kwargs
43+
**kwargs: typing.Dict
4444
) -> exec_result.ExecResult: ...
4545

46+
@typing.overload # type: ignore
4647
def execute_async(
4748
self,
4849
command: str,
49-
stdin: typing.Union[typing.AnyStr, bytearray, None]=...,
50+
stdin: typing.Union[typing.AnyStr, bytearray]=...,
5051
open_stdout: bool=...,
5152
open_stderr: bool=...,
5253
verbose: bool=...,
5354
log_mask_re: typing.Optional[str]=...,
54-
**kwargs
55-
) -> typing.Tuple[subprocess.Popen, None, typing.Optional[typing.IO], typing.Optional[typing.IO]]: ...
55+
**kwargs: typing.Dict
56+
) -> typing.Tuple[subprocess.Popen, None, None, None]: ...
57+
58+
@typing.overload
59+
def execute_async(
60+
self,
61+
command: str,
62+
stdin: None=...,
63+
open_stdout: bool=...,
64+
open_stderr: bool=...,
65+
verbose: bool=...,
66+
log_mask_re: typing.Optional[str]=...,
67+
**kwargs: typing.Dict
68+
) -> typing.Tuple[subprocess.Popen, None, typing.IO, typing.IO]: ...

tox.ini

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ commands = pip install ./ -vvv -U
8989
[testenv:pylint]
9090
usedevelop = False
9191
deps =
92-
pylint
92+
pylint<2
9393
-r{toxinidir}/CI_REQUIREMENTS.txt
9494
commands = pylint exec_helpers
9595

@@ -147,3 +147,9 @@ deps =
147147
.
148148
pipdeptree
149149
commands = pipdeptree
150+
151+
[testenv:mypy]
152+
deps =
153+
mypy>=0.620
154+
-r{toxinidir}/CI_REQUIREMENTS.txt
155+
commands = mypy --strict exec_helpers

0 commit comments

Comments
 (0)