Merge pull request #2687 from cortesi/minor1

commands: minor refactoring and command renaming
This commit is contained in:
Aldo Cortesi 2017-12-17 13:09:19 +13:00 committed by GitHub
commit 45c613f970
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 22 deletions

View File

@ -110,7 +110,7 @@ class Arg(str):
pass
def typename(t: type, ret: bool) -> str:
def typename(t: type) -> str:
"""
Translates a type to an explanatory string. If ret is True, we're
looking at a return type, else we're looking at a parameter type.
@ -153,13 +153,13 @@ class Command:
self.returntype = sig.return_annotation
def paramnames(self) -> typing.Sequence[str]:
v = [typename(i, False) for i in self.paramtypes]
v = [typename(i) for i in self.paramtypes]
if self.has_positional:
v[-1] = "*" + v[-1]
return v
def retname(self) -> str:
return typename(self.returntype, True) if self.returntype else ""
return typename(self.returntype) if self.returntype else ""
def signature_help(self) -> str:
params = " ".join(self.paramnames())

View File

@ -402,17 +402,17 @@ class ConsoleAddon:
"""
self._grideditor().cmd_delete()
@command.command("console.grideditor.readfile")
def grideditor_readfile(self, path: command.Path) -> None:
@command.command("console.grideditor.load")
def grideditor_load(self, path: command.Path) -> None:
"""
Read a file into the currrent cell.
"""
self._grideditor().cmd_read_file(path)
@command.command("console.grideditor.readfile_escaped")
def grideditor_readfile_escaped(self, path: command.Path) -> None:
@command.command("console.grideditor.load_escaped")
def grideditor_load_escaped(self, path: command.Path) -> None:
"""
Read a file containing a Python-style escaped stringinto the
Read a file containing a Python-style escaped string into the
currrent cell.
"""
self._grideditor().cmd_read_file_escaped(path)

View File

@ -145,15 +145,15 @@ def map(km):
km.add("d", "console.grideditor.delete", ["grideditor"], "Delete this row")
km.add(
"r",
"console.command console.grideditor.readfile",
"console.command console.grideditor.load",
["grideditor"],
"Read unescaped data from file"
"Read unescaped data into the current cell from file"
)
km.add(
"R",
"console.command console.grideditor.readfile_escaped",
"console.command console.grideditor.load_escaped",
["grideditor"],
"Read a Python-style escaped string from file"
"Load a Python-style escaped string into the current cell from file"
)
km.add("e", "console.grideditor.editor", ["grideditor"], "Edit in external editor")

View File

@ -151,19 +151,18 @@ def test_simple():
def test_typename():
assert command.typename(str, True) == "str"
assert command.typename(typing.Sequence[flow.Flow], True) == "[flow]"
assert command.typename(typing.Sequence[flow.Flow], False) == "[flow]"
assert command.typename(str) == "str"
assert command.typename(typing.Sequence[flow.Flow]) == "[flow]"
assert command.typename(command.Cuts, True) == "[cuts]"
assert command.typename(typing.Sequence[command.Cut], False) == "[cut]"
assert command.typename(command.Cuts) == "[cuts]"
assert command.typename(typing.Sequence[command.Cut]) == "[cut]"
assert command.typename(flow.Flow, False) == "flow"
assert command.typename(typing.Sequence[str], False) == "[str]"
assert command.typename(flow.Flow) == "flow"
assert command.typename(typing.Sequence[str]) == "[str]"
assert command.typename(command.Choice("foo"), False) == "choice"
assert command.typename(command.Path, False) == "path"
assert command.typename(command.Cmd, False) == "cmd"
assert command.typename(command.Choice("foo")) == "choice"
assert command.typename(command.Path) == "path"
assert command.typename(command.Cmd) == "cmd"
class DummyConsole: