mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-01-30 14:58:38 +00:00
commands: teach parser correct annotations for variable args
We should annotate with the base type, not the resulting sequence.
This commit is contained in:
parent
0fc24857e1
commit
56eb0441da
@ -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
|
||||
|
||||
|
@ -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.")
|
||||
|
@ -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.
|
||||
"""
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user