From c99fd71af3f754565d8942304acf699c2c3dba60 Mon Sep 17 00:00:00 2001 From: Sam Wedgwood Date: Wed, 21 Feb 2018 23:12:46 +0000 Subject: Fixed formatter.py #1rhpq - fixed multiline docstrings - added newline after docstring - changed full modulename.classname in type hints to only classname - fixed the format of the arguments to do_ --- bot/formatter.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/bot/formatter.py b/bot/formatter.py index 503ae331d..cb7c99b88 100644 --- a/bot/formatter.py +++ b/bot/formatter.py @@ -61,16 +61,37 @@ class Formatter(HelpFormatter): # get the args using the handy inspect module argspec = getfullargspec(self.command.callback) arguments = formatargspec(*argspec) - args_no_type_hints = ", ".join(argspec[0]) + for arg, annotation in argspec.annotations.items(): + # remove module name to only show class name + # discord.ext.commands.context.Context -> Context + arguments = arguments.replace(f"{annotation.__module__}.", "") + + # manipulate the argspec to make it valid python when 'calling' the do_ + args_no_type_hints = argspec.args + for kwarg in argspec.kwonlyargs: + args_no_type_hints.append("{0}={0}".format(kwarg)) + args_no_type_hints = "({0})".format(", ".join(args_no_type_hints)) # remove self from the args arguments = arguments.replace("self, ", "") args_no_type_hints = args_no_type_hints.replace("self, ", "") + # indent every line in the help message + helptext = "\n ".join(self.command.help.split("\n")) + # prepare the different sections of the help output, and add them to the paginator definition = f"async def {stripped_command}{arguments}:" - docstring = f" \"\"\"\n {self.command.help}\n \"\"\"" - invocation = f" await do_{stripped_command}({args_no_type_hints})" + doc_elems = [ + '"""', + helptext, + '"""' + ] + + docstring = "" + for elem in doc_elems: + docstring += f' {elem}\n' + + invocation = f" await do_{stripped_command}{args_no_type_hints}" self._paginator.add_line(definition) self._paginator.add_line(docstring) self._paginator.add_line(invocation) -- cgit v1.2.3