Add returns, raises, attributes sections to generated code docstrings

This commit is contained in:
Dan 2018-01-04 03:06:24 +01:00
parent 7de727a3b8
commit 64481ef56d

View File

@ -101,7 +101,7 @@ class Compiler:
if namespace: if namespace:
self.namespaces[self.section].add(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.objects[id] = "{}.{}{}.{}".format(
self.section, self.section,
@ -150,7 +150,7 @@ class Compiler:
return args + flags 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) path = "{}/{}/{}".format(dest, self.section, namespace)
os.makedirs(path, exist_ok=True) os.makedirs(path, exist_ok=True)
@ -187,21 +187,19 @@ class Compiler:
if arg_type in core_types: if arg_type in core_types:
if "int" in arg_type or arg_type == "long": if "int" in arg_type or arg_type == "long":
arg_type = "``int``" arg_type = ":obj:`int`"
elif arg_type == "double": elif arg_type == "double":
arg_type = "``float``" arg_type = ":obj:`float`"
else: else:
arg_type = "``{}``".format(arg_type.lower()) arg_type = ":obj:`{}`".format(arg_type.lower())
elif arg_type == "true": elif arg_type == "true":
arg_type = "``bool``" arg_type = ":obj:`bool`"
elif arg_type == "!X":
arg_type = "A function from :class:`pyrogram.api.functions`"
else: else:
if arg_type.startswith("Vector"): if arg_type.startswith("Vector"):
sub_type = arg_type.split("<")[1][:-1] sub_type = arg_type.split("<")[1][:-1]
if sub_type in core_types: 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: else:
arg_type = "List of :class:`pyrogram.api.types.{}`".format( arg_type = "List of :class:`pyrogram.api.types.{}`".format(
".".join( ".".join(
@ -230,6 +228,22 @@ class Compiler:
else: else:
docstring_args = "No parameters required." 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: if has_flags:
write_flags = [] write_flags = []
for i in args: for i in args: