From 65ef250aaee69c916ddba71b24ad4eb48436a722 Mon Sep 17 00:00:00 2001 From: Andris Raugulis Date: Thu, 23 Mar 2017 23:17:35 +0200 Subject: [PATCH] Upgrade to Mypy 0.501 and fix issues. Add requirements.txt. --- ssh-audit.py | 18 +++++++++++------- test/mypy-py2.sh | 7 ++++++- test/mypy-py3.sh | 6 +++++- test/mypy.ini | 10 +++++++--- test/requirements-py2.txt | 5 +++++ test/requirements-py3.txt | 6 ++++++ 6 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 test/requirements-py2.txt create mode 100644 test/requirements-py3.txt diff --git a/ssh-audit.py b/ssh-audit.py index 6087761..b482467 100755 --- a/ssh-audit.py +++ b/ssh-audit.py @@ -39,7 +39,7 @@ else: # pragma: nocover binary_type = str try: # pragma: nocover # pylint: disable=unused-import - from typing import List, Set, Sequence, Tuple, Iterable + from typing import Dict, List, Set, Sequence, Tuple, Iterable from typing import Callable, Optional, Union, Any except ImportError: # pragma: nocover pass @@ -713,7 +713,8 @@ class ReadBuf(object): def read_byte(self): # type: () -> int - return struct.unpack('B', self.read(1))[0] + v = struct.unpack('B', self.read(1))[0] # type: int + return v def read_bool(self): # type: () -> bool @@ -721,7 +722,8 @@ class ReadBuf(object): def read_int(self): # type: () -> int - return struct.unpack('>I', self.read(4))[0] + v = struct.unpack('>I', self.read(4))[0] # type: int + return v def read_list(self): # type: () -> List[text_type] @@ -1268,8 +1270,10 @@ class SSH(object): # pylint: disable=too-few-public-methods @property def maxlen(self): # type: () -> int - ml, maxlen = lambda l: max(len(i) for i in l), 0 - # type: Callable[[Sequence[text_type]], int], int + maxlen = 0 + def ml(items): + # type: (Sequence[text_type]) -> int + return max(len(i) for i in items) if self.ssh1kex is not None: maxlen = max(ml(self.ssh1kex.supported_ciphers), ml(self.ssh1kex.supported_authentications), @@ -1536,8 +1540,8 @@ class SSH(object): # pylint: disable=too-few-public-methods ipvo_len = len(ipvo) prefer_ipvo = ipvo_len > 0 prefer_ipv4 = prefer_ipvo and ipvo[0] == 4 - if len(ipvo) == 1: - family = {4: socket.AF_INET, 6: socket.AF_INET6}.get(ipvo[0]) + if ipvo_len == 1: + family = socket.AF_INET if ipvo[0] == 4 else socket.AF_INET6 else: family = socket.AF_UNSPEC try: diff --git a/test/mypy-py2.sh b/test/mypy-py2.sh index 2da29f5..17ba99e 100755 --- a/test/mypy-py2.sh +++ b/test/mypy-py2.sh @@ -7,4 +7,9 @@ if [ $? -ne 0 ]; then fi _htmldir="${_cdir}/../html/mypy-py2" mkdir -p "${_htmldir}" -env MYPYPATH="${_cdir}/stubs/" mypy --python-version 2.7 --strict-optional --config-file "${_cdir}/mypy.ini" --html-report "${_htmldir}" "${_cdir}/../ssh-audit.py" +env MYPYPATH="${_cdir}/stubs/" mypy \ +--python-version 2.7 \ +--no-warn-incomplete-stub \ +--show-error-context \ +--config-file "${_cdir}/mypy.ini" \ +--html-report "${_htmldir}" "${_cdir}/../ssh-audit.py" diff --git a/test/mypy-py3.sh b/test/mypy-py3.sh index 0b7f27c..81f2421 100755 --- a/test/mypy-py3.sh +++ b/test/mypy-py3.sh @@ -7,4 +7,8 @@ if [ $? -ne 0 ]; then fi _htmldir="${_cdir}/../html/mypy-py3" mkdir -p "${_htmldir}" -env MYPYPATH="${_cdir}/stubs/" mypy --python-version 3.5 --strict-optional --config-file "${_cdir}/mypy.ini" --html-report "${_htmldir}" "${_cdir}/../ssh-audit.py" +env MYPYPATH="${_cdir}/stubs/" mypy \ +--python-version 3.5 \ +--show-error-context \ +--config-file "${_cdir}/mypy.ini" \ +--html-report "${_htmldir}" "${_cdir}/../ssh-audit.py" diff --git a/test/mypy.ini b/test/mypy.ini index f4190cd..128ac30 100644 --- a/test/mypy.ini +++ b/test/mypy.ini @@ -4,6 +4,10 @@ follow_imports = error disallow_untyped_calls = True disallow_untyped_defs = True check_untyped_defs = True -disallow-subclassing-any = True -warn-incomplete-stub = True -warn-redundant-casts = True +disallow_subclassing_any = True +warn_incomplete_stub = True +warn_redundant_casts = True +warn_return_any = True +warn_unused_ignores = True +strict_optional = True +#strict_boolean = False diff --git a/test/requirements-py2.txt b/test/requirements-py2.txt new file mode 100644 index 0000000..bd50c11 --- /dev/null +++ b/test/requirements-py2.txt @@ -0,0 +1,5 @@ +pytest==3.0.7 +pytest-cov==2.4.0 +lxml==3.7.3 +colorama==0.3.7 +prospector==0.12.4 diff --git a/test/requirements-py3.txt b/test/requirements-py3.txt new file mode 100644 index 0000000..9957de7 --- /dev/null +++ b/test/requirements-py3.txt @@ -0,0 +1,6 @@ +pytest==3.0.7 +pytest-cov==2.4.0 +mypy==0.501 +lxml==3.7.3 +colorama==0.3.7 +prospector==0.12.4