aboutsummaryrefslogtreecommitdiffstats
path: root/test/helper_tools
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2017-07-29 20:40:00 +0200
committerMaximilian Hils <git@maximilianhils.com>2017-07-29 21:51:36 +0200
commit52da46640b46b11c69e07408d9278a056cf05c27 (patch)
tree375b2128be7657a37206f2dadb163506ed541e1c /test/helper_tools
parentc29c5dbee850b019758d4281bf144fe2da8f8495 (diff)
downloadmitmproxy-52da46640b46b11c69e07408d9278a056cf05c27.tar.gz
mitmproxy-52da46640b46b11c69e07408d9278a056cf05c27.tar.bz2
mitmproxy-52da46640b46b11c69e07408d9278a056cf05c27.zip
add option type hints
Diffstat (limited to 'test/helper_tools')
-rw-r--r--test/helper_tools/typehints_for_options.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/helper_tools/typehints_for_options.py b/test/helper_tools/typehints_for_options.py
new file mode 100644
index 00000000..8c7d006c
--- /dev/null
+++ b/test/helper_tools/typehints_for_options.py
@@ -0,0 +1,34 @@
+import typing
+from unittest import mock
+
+from mitmproxy import proxy, options
+from mitmproxy.tools import dump, console, web
+
+
+def print_typehints(opts):
+ for name, option in sorted(opts.items()):
+ print(
+ # For Python 3.6, we can just use "{}: {}".
+ "{} = None # type: {}".format(
+ name,
+ {
+ int: "int",
+ str: "str",
+ bool: "bool",
+ typing.Optional[str]: "Optional[str]",
+ typing.Sequence[str]: "Sequence[str]"
+ }[option.typespec]
+ )
+ )
+
+
+if __name__ == "__main__":
+ opts = options.Options()
+ server = proxy.server.DummyServer(None)
+
+ # initialize with all three tools here to capture tool-specific options defined in addons.
+ dump.DumpMaster(opts, server)
+ with mock.patch("sys.stdout.isatty", lambda: True):
+ console.master.ConsoleMaster(opts, server)
+ web.master.WebMaster(opts, server)
+ print_typehints(opts)