From 64481ef56dc318a71c1a2c04e516c7bceb324120 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 4 Jan 2018 03:06:24 +0100 Subject: [PATCH] Add returns, raises, attributes sections to generated code docstrings --- compiler/api/compiler.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index fab72c16..2d1e3398 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -101,7 +101,7 @@ class Compiler: if namespace: self.namespaces[self.section].add(namespace) - self.compile(namespace, name, id, args, has_flags) + self.compile(namespace, name, id, args, has_flags, type) self.objects[id] = "{}.{}{}.{}".format( self.section, @@ -150,7 +150,7 @@ class Compiler: return args + flags - def compile(self, namespace, name, id, args, has_flags): + def compile(self, namespace, name, id, args, has_flags, type): path = "{}/{}/{}".format(dest, self.section, namespace) os.makedirs(path, exist_ok=True) @@ -187,21 +187,19 @@ class Compiler: if arg_type in core_types: if "int" in arg_type or arg_type == "long": - arg_type = "``int``" + arg_type = ":obj:`int`" elif arg_type == "double": - arg_type = "``float``" + arg_type = ":obj:`float`" else: - arg_type = "``{}``".format(arg_type.lower()) + arg_type = ":obj:`{}`".format(arg_type.lower()) elif arg_type == "true": - arg_type = "``bool``" - elif arg_type == "!X": - arg_type = "A function from :class:`pyrogram.api.functions`" + arg_type = ":obj:`bool`" else: if arg_type.startswith("Vector"): sub_type = arg_type.split("<")[1][:-1] if sub_type in core_types: - arg_type = "List of ``{}``".format(self.caml(sub_type)) + arg_type = "List of :obj:`{}`".format(self.caml(sub_type)) else: arg_type = "List of :class:`pyrogram.api.types.{}`".format( ".".join( @@ -230,6 +228,22 @@ class Compiler: else: docstring_args = "No parameters required." + docstring_args = "Attributes:\n ID (:obj:`int`): ``{}``\n\n ".format(object_id) + docstring_args + + docstring_args += "\n\n Returns:\n " + if type in core_types: + docstring_args += ":obj:`{}`".format(type.lower()) + else: + docstring_args += ":class:`pyrogram.api.types.{}`".format( + ".".join( + type.split(".")[:-1] + + [self.caml(type.split(".")[-1])] + ) + ) + + if self.section == "functions": + docstring_args += "\n\n Raises:\n :class:`pyrogram.Error`" + if has_flags: write_flags = [] for i in args: