aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2017-06-13 10:26:03 +1200
committerAldo Cortesi <aldo@corte.si>2017-06-13 10:26:03 +1200
commit56eb0441da1ae85399fdbc5597cf181eeb408223 (patch)
treece2224d924d87b76419274e332c78edbda18ff13
parent0fc24857e1786973b56a40afef8e64abffbf1c98 (diff)
downloadmitmproxy-56eb0441da1ae85399fdbc5597cf181eeb408223.tar.gz
mitmproxy-56eb0441da1ae85399fdbc5597cf181eeb408223.tar.bz2
mitmproxy-56eb0441da1ae85399fdbc5597cf181eeb408223.zip
commands: teach parser correct annotations for variable args
We should annotate with the base type, not the resulting sequence.
-rw-r--r--mitmproxy/addons/core.py6
-rw-r--r--mitmproxy/command.py8
-rw-r--r--mitmproxy/tools/console/master.py6
-rw-r--r--test/mitmproxy/test_command.py2
4 files changed, 13 insertions, 9 deletions
diff --git a/mitmproxy/addons/core.py b/mitmproxy/addons/core.py
index d75949bc..b0d8ee27 100644
--- a/mitmproxy/addons/core.py
+++ b/mitmproxy/addons/core.py
@@ -10,7 +10,7 @@ from mitmproxy.net.http import status_codes
class Core:
@command.command("set")
- def set(self, *spec: typing.Sequence[str]) -> None:
+ def set(self, *spec: str) -> None:
"""
Set an option of the form "key[=value]". When the value is omitted,
booleans are set to true, strings and integers are set to None (if
@@ -18,9 +18,9 @@ class Core:
false or toggle. If multiple specs are passed, they are joined
into one separated by spaces.
"""
- spec = " ".join(spec)
+ strspec = " ".join(spec)
try:
- ctx.options.set(spec)
+ ctx.options.set(strspec)
except exceptions.OptionsError as e:
raise exceptions.CommandError(e) from e
diff --git a/mitmproxy/command.py b/mitmproxy/command.py
index 82b8fae4..2256e4ca 100644
--- a/mitmproxy/command.py
+++ b/mitmproxy/command.py
@@ -59,7 +59,7 @@ class Command:
def paramnames(self) -> typing.Sequence[str]:
v = [typename(i, False) for i in self.paramtypes]
if self.has_positional:
- v[-1] = "*" + v[-1][1:-1]
+ v[-1] = "*" + v[-1]
return v
def retname(self) -> str:
@@ -92,7 +92,11 @@ class Command:
pargs.append(parsearg(self.manager, args[i], self.paramtypes[i]))
if remainder:
- if typecheck.check_command_type(remainder, self.paramtypes[-1]):
+ chk = typecheck.check_command_type(
+ remainder,
+ typing.Sequence[self.paramtypes[-1]] # type: ignore
+ )
+ if chk:
pargs.extend(remainder)
else:
raise exceptions.CommandError("Invalid value type.")
diff --git a/mitmproxy/tools/console/master.py b/mitmproxy/tools/console/master.py
index 92e8b7a2..64e1a444 100644
--- a/mitmproxy/tools/console/master.py
+++ b/mitmproxy/tools/console/master.py
@@ -189,7 +189,7 @@ class ConsoleAddon:
@command.command("console.choose")
def console_choose(
- self, prompt: str, choices: typing.Sequence[str], *cmd: typing.Sequence[str]
+ self, prompt: str, choices: typing.Sequence[str], *cmd: str
) -> None:
"""
Prompt the user to choose from a specified list of strings, then
@@ -211,7 +211,7 @@ class ConsoleAddon:
@command.command("console.choose.cmd")
def console_choose_cmd(
- self, prompt: str, choicecmd: str, *cmd: typing.Sequence[str]
+ self, prompt: str, choicecmd: str, *cmd: str
) -> None:
"""
Prompt the user to choose from a list of strings returned by a
@@ -234,7 +234,7 @@ class ConsoleAddon:
)
@command.command("console.command")
- def console_command(self, *partial: typing.Sequence[str]) -> None:
+ def console_command(self, *partial: str) -> None:
"""
Prompt the user to edit a command with a (possilby empty) starting value.
"""
diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py
index 958328b2..87432163 100644
--- a/test/mitmproxy/test_command.py
+++ b/test/mitmproxy/test_command.py
@@ -22,7 +22,7 @@ class TAddon:
def empty(self) -> None:
pass
- def varargs(self, one: str, *var: typing.Sequence[str]) -> typing.Sequence[str]:
+ def varargs(self, one: str, *var: str) -> typing.Sequence[str]:
return list(var)