aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2016-12-28 14:21:19 +0100
committerMaximilian Hils <git@maximilianhils.com>2016-12-28 14:21:19 +0100
commiteab360a02b13b0dcc659546ddde383cc5a5b88bb (patch)
tree142f7777a79de03845ff715237d8164ffd5ca325
parent0929e74b4e82e3ee9ba1d6ddb7a54a68240a4282 (diff)
downloadmitmproxy-eab360a02b13b0dcc659546ddde383cc5a5b88bb.tar.gz
mitmproxy-eab360a02b13b0dcc659546ddde383cc5a5b88bb.tar.bz2
mitmproxy-eab360a02b13b0dcc659546ddde383cc5a5b88bb.zip
fix IO type checking
-rw-r--r--mitmproxy/utils/typecheck.py2
-rw-r--r--test/mitmproxy/utils/test_typecheck.py8
2 files changed, 10 insertions, 0 deletions
diff --git a/mitmproxy/utils/typecheck.py b/mitmproxy/utils/typecheck.py
index 20af0150..ae1a507d 100644
--- a/mitmproxy/utils/typecheck.py
+++ b/mitmproxy/utils/typecheck.py
@@ -65,6 +65,8 @@ def check_type(attr_name: str, value: typing.Any, typeinfo: type) -> None:
elif typename.startswith("typing.IO"):
if hasattr(value, "read"):
return
+ else:
+ raise e
elif not isinstance(value, typeinfo):
raise e
diff --git a/test/mitmproxy/utils/test_typecheck.py b/test/mitmproxy/utils/test_typecheck.py
index 75c932e5..0ed440eb 100644
--- a/test/mitmproxy/utils/test_typecheck.py
+++ b/test/mitmproxy/utils/test_typecheck.py
@@ -1,7 +1,9 @@
+import io
import typing
import mock
import pytest
+
from mitmproxy.utils import typecheck
@@ -66,3 +68,9 @@ def test_check_sequence():
m.__str__ = lambda self: "typing.Sequence"
m.__parameters__ = (int,)
typecheck.check_type("foo", [10], m)
+
+
+def test_check_io():
+ typecheck.check_type("foo", io.StringIO(), typing.IO[str])
+ with pytest.raises(TypeError):
+ typecheck.check_type("foo", "foo", typing.IO[str])