aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/utils
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2017-03-16 16:50:41 +1300
committerAldo Cortesi <aldo@corte.si>2017-03-17 08:13:47 +1300
commit5192810ff6a41e62e41d16fcf636663d177a1232 (patch)
treec3fc61680fb63af27df357a198584610772a47b0 /mitmproxy/utils
parenteac210829e51d988b7090b448037de6d41d5dfe9 (diff)
downloadmitmproxy-5192810ff6a41e62e41d16fcf636663d177a1232.tar.gz
mitmproxy-5192810ff6a41e62e41d16fcf636663d177a1232.tar.bz2
mitmproxy-5192810ff6a41e62e41d16fcf636663d177a1232.zip
Make mypy succeed with imports on master.py
We get little benefit from our mypy QA checks at the moment, because we skip imports. This patch is what's needed to make mypy succeed with imports on a single file: master.py It also updates mypy to the current version, and enables a QA check. Mypy bugs I encountered: dict.update with kwargs not supported: https://github.com/python/mypy/issues/1031 property setters and getters must be adjacent: https://github.com/python/mypy/issues/1465
Diffstat (limited to 'mitmproxy/utils')
-rw-r--r--mitmproxy/utils/strutils.py6
-rw-r--r--mitmproxy/utils/typecheck.py12
2 files changed, 9 insertions, 9 deletions
diff --git a/mitmproxy/utils/strutils.py b/mitmproxy/utils/strutils.py
index 29465615..1b90c2e5 100644
--- a/mitmproxy/utils/strutils.py
+++ b/mitmproxy/utils/strutils.py
@@ -1,11 +1,11 @@
import re
import codecs
-from typing import AnyStr, Optional
+from typing import AnyStr, Optional, cast
def always_bytes(str_or_bytes: Optional[AnyStr], *encode_args) -> Optional[bytes]:
if isinstance(str_or_bytes, bytes) or str_or_bytes is None:
- return str_or_bytes
+ return cast(Optional[bytes], str_or_bytes)
elif isinstance(str_or_bytes, str):
return str_or_bytes.encode(*encode_args)
else:
@@ -18,7 +18,7 @@ def always_str(str_or_bytes: Optional[AnyStr], *decode_args) -> Optional[str]:
str_or_bytes unmodified, if
"""
if isinstance(str_or_bytes, str) or str_or_bytes is None:
- return str_or_bytes
+ return cast(Optional[str], str_or_bytes)
elif isinstance(str_or_bytes, bytes):
return str_or_bytes.decode(*decode_args)
else:
diff --git a/mitmproxy/utils/typecheck.py b/mitmproxy/utils/typecheck.py
index bdd83ee6..e8e2121e 100644
--- a/mitmproxy/utils/typecheck.py
+++ b/mitmproxy/utils/typecheck.py
@@ -25,10 +25,10 @@ def check_type(name: str, value: typing.Any, typeinfo: type) -> None:
if typename.startswith("typing.Union"):
try:
- types = typeinfo.__args__
+ types = typeinfo.__args__ # type: ignore
except AttributeError:
# Python 3.5.x
- types = typeinfo.__union_params__
+ types = typeinfo.__union_params__ # type: ignore
for T in types:
try:
@@ -40,10 +40,10 @@ def check_type(name: str, value: typing.Any, typeinfo: type) -> None:
raise e
elif typename.startswith("typing.Tuple"):
try:
- types = typeinfo.__args__
+ types = typeinfo.__args__ # type: ignore
except AttributeError:
# Python 3.5.x
- types = typeinfo.__tuple_params__
+ types = typeinfo.__tuple_params__ # type: ignore
if not isinstance(value, (tuple, list)):
raise e
@@ -54,10 +54,10 @@ def check_type(name: str, value: typing.Any, typeinfo: type) -> None:
return
elif typename.startswith("typing.Sequence"):
try:
- T = typeinfo.__args__[0]
+ T = typeinfo.__args__[0] # type: ignore
except AttributeError:
# Python 3.5.0
- T = typeinfo.__parameters__[0]
+ T = typeinfo.__parameters__[0] # type: ignore
if not isinstance(value, (tuple, list)):
raise e