commands: if no explicit return type is specified, assume None

This is going to be a super common error for addon authors, so we might as well
handle it.
This commit is contained in:
Aldo Cortesi 2018-05-12 10:15:08 +12:00
parent 75d30212c2
commit 6dff8c58ad
2 changed files with 17 additions and 1 deletions

View File

@ -58,7 +58,10 @@ class Command:
if i.kind == i.VAR_POSITIONAL: if i.kind == i.VAR_POSITIONAL:
self.has_positional = True self.has_positional = True
self.paramtypes = [v.annotation for v in sig.parameters.values()] self.paramtypes = [v.annotation for v in sig.parameters.values()]
self.returntype = sig.return_annotation if sig.return_annotation == inspect._empty:
self.returntype = None
else:
self.returntype = sig.return_annotation
def paramnames(self) -> typing.Sequence[str]: def paramnames(self) -> typing.Sequence[str]:
v = [typename(i) for i in self.paramtypes] v = [typename(i) for i in self.paramtypes]

View File

@ -55,7 +55,20 @@ class TAddon:
pass pass
class TypeErrAddon:
@command.command("noret")
def noret(self):
pass
class TestCommand: class TestCommand:
def test_typecheck(self):
with taddons.context(loadcore=False) as tctx:
cm = command.CommandManager(tctx.master)
a = TypeErrAddon()
c = command.Command(cm, "noret", a.noret)
print(c.signature_help())
def test_varargs(self): def test_varargs(self):
with taddons.context() as tctx: with taddons.context() as tctx:
cm = command.CommandManager(tctx.master) cm = command.CommandManager(tctx.master)