Rework API compiler
This commit is contained in:
parent
5678621b04
commit
2117c9a1c5
@ -54,12 +54,6 @@ def capit(s: str):
|
|||||||
return "".join([i[0].upper() + i[1:] for i in s.split("_")])
|
return "".join([i[0].upper() + i[1:] for i in s.split("_")])
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# def caml(s: str):
|
|
||||||
# r = snek(s).split("_")
|
|
||||||
# return "".join([str(i.title()) for i in r])
|
|
||||||
|
|
||||||
|
|
||||||
def sort_args(args):
|
def sort_args(args):
|
||||||
"""Put flags at the end"""
|
"""Put flags at the end"""
|
||||||
args = args.copy()
|
args = args.copy()
|
||||||
@ -147,6 +141,16 @@ def start():
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
by_types = {}
|
||||||
|
for c in combinators:
|
||||||
|
return_type = capit(c.return_type)
|
||||||
|
|
||||||
|
if c.section == "types":
|
||||||
|
if return_type not in by_types:
|
||||||
|
by_types[return_type] = []
|
||||||
|
|
||||||
|
by_types[return_type].append(".".join(filter(None, [c.namespace, capit(c.name)])))
|
||||||
|
|
||||||
total = len(combinators)
|
total = len(combinators)
|
||||||
current = 0
|
current = 0
|
||||||
for c in combinators: # type: Combinator
|
for c in combinators: # type: Combinator
|
||||||
@ -238,41 +242,76 @@ def start():
|
|||||||
|
|
||||||
docstring_args = "Attributes:\n ID (:obj:`int`): ``{}``\n\n ".format(c.id) + docstring_args
|
docstring_args = "Attributes:\n ID (:obj:`int`): ``{}``\n\n ".format(c.id) + docstring_args
|
||||||
|
|
||||||
docstring_args += "\n\n Returns:\n "
|
if c.section == "functions":
|
||||||
if c.return_type in core_types:
|
docstring_args += "\n\n Returns:\n "
|
||||||
if "int" in c.return_type or c.return_type == "long":
|
if c.return_type in core_types:
|
||||||
return_type = ":obj:`int`"
|
if "int" in c.return_type or c.return_type == "long":
|
||||||
elif c.return_type == "double":
|
return_type = ":obj:`int`"
|
||||||
return_type = ":obj:`float`"
|
elif c.return_type == "double":
|
||||||
else:
|
return_type = ":obj:`float`"
|
||||||
return_type = ":obj:`{}`".format(c.return_type.lower())
|
|
||||||
else:
|
|
||||||
if c.return_type.startswith("Vector"):
|
|
||||||
sub_type = c.return_type.split("<")[1][:-1]
|
|
||||||
|
|
||||||
if sub_type in core_types:
|
|
||||||
if "int" in sub_type or sub_type == "long":
|
|
||||||
return_type = "List of :obj:`int`"
|
|
||||||
elif sub_type == "double":
|
|
||||||
return_type = "List of :obj:`float`"
|
|
||||||
else:
|
|
||||||
return_type = "List of :obj:`{}`".format(c.return_type.lower())
|
|
||||||
else:
|
else:
|
||||||
return_type = "List of :class:`pyrogram.api.types.{}`".format(
|
return_type = ":obj:`{}`".format(c.return_type.lower())
|
||||||
".".join(
|
|
||||||
sub_type.split(".")[:-1]
|
|
||||||
+ [capit(sub_type.split(".")[-1])]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
return_type = ":class:`pyrogram.api.types.{}`".format(
|
if c.return_type.startswith("Vector"):
|
||||||
".".join(
|
sub_type = c.return_type.split("<")[1][:-1]
|
||||||
c.return_type.split(".")[:-1]
|
|
||||||
+ [capit(c.return_type.split(".")[-1])]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
docstring_args += return_type
|
if sub_type in core_types:
|
||||||
|
if "int" in sub_type or sub_type == "long":
|
||||||
|
return_type = "List of :obj:`int`"
|
||||||
|
elif sub_type == "double":
|
||||||
|
return_type = "List of :obj:`float`"
|
||||||
|
else:
|
||||||
|
return_type = "List of :obj:`{}`".format(c.return_type.lower())
|
||||||
|
else:
|
||||||
|
if c.section == "functions":
|
||||||
|
try:
|
||||||
|
constructors = by_types[capit(sub_type)]
|
||||||
|
except KeyError:
|
||||||
|
return_type = "List of :class:`pyrogram.api.types.{}`".format(
|
||||||
|
".".join(
|
||||||
|
sub_type.split(".")[:-1]
|
||||||
|
+ [capit(sub_type.split(".")[-1])]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
constructors = ["List of :class:`pyrogram.api.types.{}`".format(
|
||||||
|
".".join(
|
||||||
|
i.split(".")[:-1]
|
||||||
|
+ [capit(i.split(".")[-1])]
|
||||||
|
)
|
||||||
|
) for i in constructors]
|
||||||
|
|
||||||
|
return_type = " | ".join(constructors)
|
||||||
|
else:
|
||||||
|
return_type = "List of :class:`pyrogram.api.types.{}`".format(
|
||||||
|
".".join(
|
||||||
|
sub_type.split(".")[:-1]
|
||||||
|
+ [capit(sub_type.split(".")[-1])]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
if c.section == "functions":
|
||||||
|
try:
|
||||||
|
constructors = by_types[capit(c.return_type)]
|
||||||
|
except KeyError:
|
||||||
|
return_type = ":class:`pyrogram.api.types.{}`".format(
|
||||||
|
".".join(filter(None, [c.namespace, capit(c.name)]))
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
constructors = [":class:`pyrogram.api.types.{}`".format(
|
||||||
|
".".join(
|
||||||
|
i.split(".")[:-1]
|
||||||
|
+ [capit(i.split(".")[-1])]
|
||||||
|
)
|
||||||
|
) for i in constructors]
|
||||||
|
|
||||||
|
return_type = " | ".join(constructors)
|
||||||
|
else:
|
||||||
|
return_type = ":class:`pyrogram.api.types.{}`".format(
|
||||||
|
".".join(filter(None, [c.namespace, capit(c.name)]))
|
||||||
|
)
|
||||||
|
|
||||||
|
docstring_args += return_type
|
||||||
|
|
||||||
if c.section == "functions":
|
if c.section == "functions":
|
||||||
docstring_args += "\n\n Raises:\n :class:`pyrogram.Error`"
|
docstring_args += "\n\n Raises:\n :class:`pyrogram.Error`"
|
||||||
|
Loading…
Reference in New Issue
Block a user