From 2b500f234fc8cf5d7922218ac1fb12e9874c2f61 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Mon, 24 Apr 2017 13:39:59 +0200 Subject: typecheck: add support for typing.Any --- mitmproxy/utils/typecheck.py | 2 ++ test/mitmproxy/utils/test_typecheck.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/mitmproxy/utils/typecheck.py b/mitmproxy/utils/typecheck.py index 5df4ea4b..628ea642 100644 --- a/mitmproxy/utils/typecheck.py +++ b/mitmproxy/utils/typecheck.py @@ -68,5 +68,7 @@ def check_type(name: str, value: typing.Any, typeinfo: typing.Any) -> None: return else: raise e + elif typename.startswith("typing.Any"): + return elif not isinstance(value, typeinfo): raise e diff --git a/test/mitmproxy/utils/test_typecheck.py b/test/mitmproxy/utils/test_typecheck.py index d99a914f..fd0c6e0c 100644 --- a/test/mitmproxy/utils/test_typecheck.py +++ b/test/mitmproxy/utils/test_typecheck.py @@ -79,3 +79,9 @@ 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]) + + +def test_check_any(): + typecheck.check_type("foo", 42, typing.Any) + typecheck.check_type("foo", object(), typing.Any) + typecheck.check_type("foo", None, typing.Any) -- cgit v1.2.3