Skip to content

Commit 18dbcd7

Browse files
committed
MyPy 0.650 - new checks
(cherry picked from commit 6077362)
1 parent 2416f1f commit 18dbcd7

File tree

8 files changed

+28
-26
lines changed

8 files changed

+28
-26
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
install:
7676
- *upgrade_python_toolset
7777
- *install_deps
78-
- pip install --upgrade "mypy >= 0.641"
78+
- pip install --upgrade "mypy >= 0.650"
7979
script:
8080
- mypy --strict exec_helpers
8181

exec_helpers/_ssh_client_base.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ class _MemorizedSSH(abc.ABCMeta):
121121

122122
@classmethod
123123
def __prepare__( # pylint: disable=unused-argument
124-
mcs: typing.Type["_MemorizedSSH"], name: str, bases: typing.Iterable[typing.Type], **kwargs: typing.Any
125-
) -> collections.OrderedDict:
124+
mcs: typing.Type["_MemorizedSSH"], name: str, bases: typing.Iterable[type], **kwargs: typing.Any
125+
) -> "collections.OrderedDict[str, typing.Any]":
126126
"""Metaclass magic for object storage.
127127
128128
.. versionadded:: 1.2.0
@@ -516,7 +516,7 @@ def reconnect(self) -> None:
516516

517517
self.__connect()
518518

519-
def sudo(self, enforce: typing.Optional[bool] = None) -> "typing.ContextManager":
519+
def sudo(self, enforce: typing.Optional[bool] = None) -> "typing.ContextManager[None]":
520520
"""Call contextmanager for sudo mode change.
521521
522522
:param enforce: Enforce sudo enabled or disabled. By default: None
@@ -526,7 +526,7 @@ def sudo(self, enforce: typing.Optional[bool] = None) -> "typing.ContextManager"
526526
"""
527527
return self.__get_sudo(ssh=self, enforce=enforce)
528528

529-
def keepalive(self, enforce: bool = True) -> "typing.ContextManager":
529+
def keepalive(self, enforce: bool = True) -> "typing.ContextManager[None]":
530530
"""Call contextmanager with keepalive mode change.
531531
532532
:param enforce: Enforce keepalive enabled or disabled.
@@ -694,7 +694,7 @@ def poll_pipes() -> None:
694694

695695
# pylint: disable=assignment-from-no-return
696696
# noinspection PyNoneFunctionAssignment
697-
future = poll_pipes() # type: concurrent.futures.Future
697+
future = poll_pipes()
698698
# pylint: enable=assignment-from-no-return
699699

700700
concurrent.futures.wait([future], timeout)
@@ -877,14 +877,12 @@ def get_result(remote: "SSHClientBase") -> exec_result.ExecResult:
877877
errors = {}
878878
raised_exceptions = {}
879879

880-
(_, not_done) = concurrent.futures.wait(
881-
list(futures.values()), timeout=timeout
882-
) # type: typing.Set[concurrent.futures.Future], typing.Set[concurrent.futures.Future]
880+
_, not_done = concurrent.futures.wait(list(futures.values()), timeout=timeout)
883881

884882
for fut in not_done: # pragma: no cover
885883
fut.cancel()
886884

887-
for (remote, future) in futures.items(): # type: SSHClientBase, concurrent.futures.Future
885+
for (remote, future) in futures.items():
888886
try:
889887
result = future.result()
890888
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
@@ -220,7 +220,7 @@ def _poll_stream(
220220

221221
def read_stdout(
222222
self,
223-
src: typing.Optional[typing.Iterable] = None,
223+
src: typing.Optional[typing.Iterable[bytes]] = None,
224224
log: typing.Optional[logging.Logger] = None,
225225
verbose: bool = False,
226226
) -> None:
@@ -247,7 +247,7 @@ def read_stdout(
247247

248248
def read_stderr(
249249
self,
250-
src: typing.Optional[typing.Iterable] = None,
250+
src: typing.Optional[typing.Iterable[bytes]] = None,
251251
log: typing.Optional[logging.Logger] = None,
252252
verbose: bool = False,
253253
) -> None:

exec_helpers/metaclasses.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class SingletonMeta(abc.ABCMeta):
2727
Main goals: not need to implement __new__ in singleton classes
2828
"""
2929

30-
_instances = {} # type: typing.Dict[typing.Type, typing.Any]
30+
_instances = {} # type: typing.Dict[type, typing.Any]
3131
_lock = threading.RLock() # type: threading.RLock
3232

3333
def __call__(cls: "SingletonMeta", *args: typing.Any, **kwargs: typing.Any) -> typing.Any:
@@ -40,8 +40,8 @@ def __call__(cls: "SingletonMeta", *args: typing.Any, **kwargs: typing.Any) -> t
4040

4141
@classmethod
4242
def __prepare__( # pylint: disable=unused-argument
43-
mcs: typing.Type["SingletonMeta"], name: str, bases: typing.Iterable[typing.Type], **kwargs: typing.Any
44-
) -> collections.OrderedDict:
43+
mcs: typing.Type["SingletonMeta"], name: str, bases: typing.Iterable[type], **kwargs: typing.Any
44+
) -> "collections.OrderedDict[str, typing.Any]":
4545
"""Metaclass magic for object storage.
4646
4747
.. versionadded:: 1.2.0
@@ -58,8 +58,12 @@ def __init__(cls, name: str, bases: typing.Tuple[type, ...], namespace: typing.D
5858
cls.__lock = threading.RLock()
5959

6060
def __new__( # pylint: disable=arguments-differ
61-
mcs, name: str, bases: typing.Tuple[type, ...], namespace: typing.Dict[str, typing.Any], **kwargs: typing.Any
62-
) -> typing.Type:
61+
mcs: typing.Type["SingleLock"],
62+
name: str,
63+
bases: typing.Tuple[type, ...],
64+
namespace: typing.Dict[str, typing.Any],
65+
**kwargs: typing.Any
66+
) -> "SingleLock":
6367
"""Create lock property for class instances."""
6468
namespace["lock"] = property(fget=lambda self: self.__class__.lock)
6569
return super().__new__(mcs, name, bases, namespace, **kwargs) # type: ignore
@@ -71,8 +75,8 @@ def lock(cls) -> threading.RLock:
7175

7276
@classmethod
7377
def __prepare__( # pylint: disable=unused-argument
74-
mcs: typing.Type["SingleLock"], name: str, bases: typing.Iterable[typing.Type], **kwargs: typing.Any
75-
) -> collections.OrderedDict:
78+
mcs: typing.Type["SingleLock"], name: str, bases: typing.Iterable[type], **kwargs: typing.Any
79+
) -> "collections.OrderedDict[str, typing.Any]":
7680
"""Metaclass magic for object storage.
7781
7882
.. versionadded:: 1.2.0

exec_helpers/ssh_auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def key_filename(self) -> typing.Union[typing.List[str], str, None]:
113113
"""
114114
return copy.deepcopy(self.__key_filename)
115115

116-
def enter_password(self, tgt: typing.IO) -> None:
116+
def enter_password(self, tgt: typing.BinaryIO) -> None:
117117
"""Enter password to STDIN.
118118
119119
Note: required for 'sudo' call
@@ -122,7 +122,7 @@ def enter_password(self, tgt: typing.IO) -> None:
122122
:type tgt: file
123123
"""
124124
# noinspection PyTypeChecker
125-
tgt.write("{}\n".format(self.__password))
125+
tgt.write("{}\n".format(self.__password if self.__password is not None else "").encode("utf-8"))
126126

127127
def connect(
128128
self,

exec_helpers/subprocess_runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ def close_streams() -> None:
141141

142142
# pylint: disable=assignment-from-no-return
143143
# noinspection PyNoneFunctionAssignment
144-
stdout_future = poll_stdout() # type: concurrent.futures.Future
144+
stdout_future = poll_stdout()
145145
# noinspection PyNoneFunctionAssignment
146-
stderr_future = poll_stderr() # type: concurrent.futures.Future
146+
stderr_future = poll_stderr()
147147
# pylint: enable=assignment-from-no-return
148148

149149
try:

test/test_sshauth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ def test_001_init_checks(run_parameters) -> None:
103103
int_keys = get_internal_keys(**run_parameters)
104104

105105
assert auth.username == username
106-
with contextlib.closing(io.StringIO()) as tgt:
106+
with contextlib.closing(io.BytesIO()) as tgt:
107107
auth.enter_password(tgt)
108-
assert tgt.getvalue() == "{}\n".format(run_parameters.get("password", None))
108+
assert tgt.getvalue() == "{}\n".format(run_parameters.get("password", "")).encode("utf-8")
109109

110110
key = run_parameters.get("key", None)
111111
if key is not None:

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ commands = pipdeptree
122122

123123
[testenv:mypy]
124124
deps =
125-
mypy>=0.641
125+
mypy>=0.650
126126
-r{toxinidir}/CI_REQUIREMENTS.txt
127127
usedevelop = False
128128
commands = mypy --strict exec_helpers

0 commit comments

Comments
 (0)