From ac22aee2f512cefd298fe0d9563a5de0ef7e42ee Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sat, 16 Nov 2019 14:56:01 +0100 Subject: [PATCH] cleanup mypy usage --- .landscape.yml | 20 -------------------- examples/complex/change_upstream_proxy.py | 2 +- examples/complex/sslstrip.py | 1 + examples/complex/xss_scanner.py | 2 ++ release/cibuild.py | 4 +++- setup.cfg | 6 ++++++ setup.py | 4 +++- tox.ini | 3 +-- 8 files changed, 17 insertions(+), 25 deletions(-) delete mode 100644 .landscape.yml diff --git a/.landscape.yml b/.landscape.yml deleted file mode 100644 index b6a45ed71..000000000 --- a/.landscape.yml +++ /dev/null @@ -1,20 +0,0 @@ -ignore-paths: - - docs - - examples - - mitmproxy/contrib - - web -max-line-length: 140 -pylint: - options: - dummy-variables-rgx: _$|.+_$|dummy_.+ - disable: - - missing-docstring - - protected-access - - too-few-public-methods - - too-many-arguments - - too-many-instance-attributes - - too-many-locals - - too-many-public-methods - - too-many-return-statements - - too-many-statements - - unpacking-non-sequence diff --git a/examples/complex/change_upstream_proxy.py b/examples/complex/change_upstream_proxy.py index 089a9df58..a0e7e5728 100644 --- a/examples/complex/change_upstream_proxy.py +++ b/examples/complex/change_upstream_proxy.py @@ -24,4 +24,4 @@ def request(flow: http.HTTPFlow) -> None: return address = proxy_address(flow) if flow.live: - flow.live.change_upstream_proxy_server(address) + flow.live.change_upstream_proxy_server(address) # type: ignore diff --git a/examples/complex/sslstrip.py b/examples/complex/sslstrip.py index 69b9ea9ed..8b9042167 100644 --- a/examples/complex/sslstrip.py +++ b/examples/complex/sslstrip.py @@ -31,6 +31,7 @@ def request(flow: http.HTTPFlow) -> None: def response(flow: http.HTTPFlow) -> None: + assert flow.response flow.response.headers.pop('Strict-Transport-Security', None) flow.response.headers.pop('Public-Key-Pins', None) diff --git a/examples/complex/xss_scanner.py b/examples/complex/xss_scanner.py index d5f4aaab2..2a45511a8 100755 --- a/examples/complex/xss_scanner.py +++ b/examples/complex/xss_scanner.py @@ -395,8 +395,10 @@ def get_XSS_data(body: Union[str, bytes], request_URL: str, injection_point: str # response is mitmproxy's entry point def response(flow: http.HTTPFlow) -> None: + assert flow.response cookies_dict = get_cookies(flow) resp = flow.response.get_text(strict=False) + assert resp # Example: http://xss.guru/unclaimedScriptTag.html find_unclaimed_URLs(resp, flow.request.url) results = test_end_of_URL_injection(resp, flow.request.url, cookies_dict) diff --git a/release/cibuild.py b/release/cibuild.py index 820606398..799c79294 100755 --- a/release/cibuild.py +++ b/release/cibuild.py @@ -190,7 +190,9 @@ class BuildEnviron: """ with open(pathlib.Path(self.root_dir) / "mitmproxy" / "version.py") as f: contents = f.read() - version = re.search(r'^VERSION = "(.+?)"', contents, re.M).group(1) + match = re.search(r'^VERSION = "(.+?)"', contents, re.M) + assert match + version = match.group(1) if self.is_prod_release: # For production releases, we require strict version equality diff --git a/setup.cfg b/setup.cfg index e7643b087..a2c49f48d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,12 +19,18 @@ exclude_lines = pragma: no cover raise NotImplementedError() +[mypy] +ignore_missing_imports = True + [mypy-mitmproxy.contrib.*] ignore_errors = True [mypy-tornado.*] ignore_errors = True +[mypy-test.*] +ignore_errors = True + [tool:full_coverage] exclude = mitmproxy/proxy/protocol/base.py diff --git a/setup.py b/setup.py index 9343dd997..fb23fd69a 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,9 @@ with open(os.path.join(here, 'README.rst'), encoding='utf-8') as f: long_description = f.read() with open(os.path.join(here, "mitmproxy", "version.py")) as f: - VERSION = re.search(r'VERSION = "(.+?)"', f.read()).group(1) + match = re.search(r'VERSION = "(.+?)"', f.read()) + assert match + VERSION = match.group(1) setup( name="mitmproxy", diff --git a/tox.ini b/tox.ini index 8c8fbaa21..3df2bd406 100644 --- a/tox.ini +++ b/tox.ini @@ -31,8 +31,7 @@ commands = flake8 --jobs 8 mitmproxy pathod examples test release python ./test/filename_matching.py rstcheck README.rst - mypy --ignore-missing-imports ./mitmproxy ./pathod - mypy --ignore-missing-imports --follow-imports=skip ./examples/simple/ ./examples/pathod/ ./examples/complex/ + mypy . [testenv:individual_coverage] deps =