Skip to content

Commit 202b09f

Browse files
committed
MyPy 0.650 - new checks
(cherry picked from commit 6077362)
1 parent c0c6f6b commit 202b09f

File tree

7 files changed

+16
-18
lines changed

7 files changed

+16
-18
lines changed

exec_helpers/_ssh_client_base.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ def reconnect(self): # type: () -> None
496496

497497
self.__connect()
498498

499-
def sudo(self, enforce=None): # type: (typing.Optional[bool]) -> typing.ContextManager
499+
def sudo(self, enforce=None): # type: (typing.Optional[bool]) -> typing.ContextManager[None]
500500
"""Call contextmanager for sudo mode change.
501501
502502
:param enforce: Enforce sudo enabled or disabled. By default: None
@@ -506,7 +506,7 @@ def sudo(self, enforce=None): # type: (typing.Optional[bool]) -> typing.Context
506506
"""
507507
return self.__get_sudo(ssh=self, enforce=enforce)
508508

509-
def keepalive(self, enforce=True): # type: (bool) -> typing.ContextManager
509+
def keepalive(self, enforce=True): # type: (bool) -> typing.ContextManager[None]
510510
"""Call contextmanager with keepalive mode change.
511511
512512
:param enforce: Enforce keepalive enabled or disabled.
@@ -665,7 +665,7 @@ def poll_pipes(): # type: () -> None
665665

666666
# pylint: disable=assignment-from-no-return
667667
# noinspection PyNoneFunctionAssignment
668-
future = poll_pipes() # type: concurrent.futures.Future
668+
future = poll_pipes()
669669
# pylint: enable=assignment-from-no-return
670670

671671
concurrent.futures.wait([future], timeout)
@@ -841,14 +841,12 @@ def get_result(remote): # type: (SSHClientBase) -> exec_result.ExecResult
841841
errors = {}
842842
raised_exceptions = {}
843843

844-
(_, not_done) = concurrent.futures.wait(
845-
list(futures.values()), timeout=timeout
846-
) # type: typing.Set[concurrent.futures.Future], typing.Set[concurrent.futures.Future]
844+
_, not_done = concurrent.futures.wait(list(futures.values()), timeout=timeout)
847845

848846
for fut in not_done: # pragma: no cover
849847
fut.cancel()
850848

851-
for (remote, future) in futures.items(): # type: SSHClientBase, concurrent.futures.Future
849+
for (remote, future) in futures.items():
852850
try:
853851
result = future.result()
854852
results[(remote.hostname, remote.port)] = result

exec_helpers/exec_result.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def _poll_stream(
227227

228228
def read_stdout(
229229
self,
230-
src=None, # type: typing.Optional[typing.Iterable]
230+
src=None, # type: typing.Optional[typing.Iterable[bytes]]
231231
log=None, # type: typing.Optional[logging.Logger]
232232
verbose=False, # type: bool
233233
): # type: (...) -> None
@@ -254,7 +254,7 @@ def read_stdout(
254254

255255
def read_stderr(
256256
self,
257-
src=None, # type: typing.Optional[typing.Iterable]
257+
src=None, # type: typing.Optional[typing.Iterable[bytes]]
258258
log=None, # type: typing.Optional[logging.Logger]
259259
verbose=False, # type: bool
260260
): # type: (...) -> None

exec_helpers/metaclasses.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class SingletonMeta(abc.ABCMeta):
3333
Main goals: not need to implement __new__ in singleton classes
3434
"""
3535

36-
_instances = {} # type: typing.Dict[typing.Type, typing.Any]
36+
_instances = {} # type: typing.Dict[type, typing.Any]
3737
_lock = threading.RLock() # type: threading.RLock
3838

3939
def __call__(cls, *args, **kwargs): # type: (SingletonMeta, typing.Any, typing.Any) -> typing.Any
@@ -57,7 +57,7 @@ def __init__(
5757

5858
def __new__( # pylint: disable=arguments-differ
5959
mcs, name, bases, namespace, **kwargs
60-
): # type: (str, typing.Tuple[type, ...], typing.Dict[str, typing.Any], typing.Any) -> typing.Type
60+
): # type: (str, typing.Tuple[type, ...], typing.Dict[str, typing.Any], typing.Any) -> "SingleLock"
6161
"""Create lock property for class instances."""
6262
namespace["lock"] = property(fget=lambda self: self.__class__.lock)
6363
return super(SingleLock, mcs).__new__(mcs, name, bases, namespace, **kwargs) # type: ignore

exec_helpers/ssh_auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def key_filename(self): # type: () -> typing.Union[typing.List[str], str, None]
117117
"""
118118
return copy.deepcopy(self.__key_filename)
119119

120-
def enter_password(self, tgt): # type: (typing.IO) -> None
120+
def enter_password(self, tgt): # type: (typing.BinaryIO) -> None
121121
"""Enter password to STDIN.
122122
123123
Note: required for 'sudo' call
@@ -126,7 +126,7 @@ def enter_password(self, tgt): # type: (typing.IO) -> None
126126
:type tgt: file
127127
"""
128128
# noinspection PyTypeChecker
129-
tgt.write("{}\n".format(self.__password))
129+
tgt.write("{}\n".format(self.__password if self.__password is not None else "").encode("utf-8"))
130130

131131
def connect(
132132
self,

exec_helpers/subprocess_runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ def close_streams(): # type: () -> None
127127

128128
# pylint: disable=assignment-from-no-return
129129
# noinspection PyNoneFunctionAssignment
130-
stdout_future = poll_stdout() # type: concurrent.futures.Future
130+
stdout_future = poll_stdout()
131131
# noinspection PyNoneFunctionAssignment
132-
stderr_future = poll_stderr() # type: concurrent.futures.Future
132+
stderr_future = poll_stderr()
133133
# pylint: enable=assignment-from-no-return
134134

135135
concurrent.futures.wait([stdout_future, stderr_future], timeout=timeout) # Wait real timeout here

test/test_sshauth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ def test_001_init_checks(run_parameters):
106106
int_keys = get_internal_keys(**run_parameters)
107107

108108
assert auth.username == username
109-
with contextlib.closing(io.StringIO()) as tgt:
109+
with contextlib.closing(io.BytesIO()) as tgt:
110110
auth.enter_password(tgt)
111-
assert tgt.getvalue() == "{}\n".format(run_parameters.get("password", None))
111+
assert tgt.getvalue() == "{}\n".format(run_parameters.get("password", "")).encode("utf-8")
112112

113113
key = run_parameters.get("key", None)
114114
if key is not None:

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,6 @@ commands = pipdeptree
140140
[testenv:mypy]
141141
usedevelop = False
142142
deps =
143-
mypy>=0.630
143+
mypy>=0.650
144144
-r{toxinidir}/CI_REQUIREMENTS.txt
145145
commands = mypy --strict exec_helpers

0 commit comments

Comments
 (0)