mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-30 17:43:32 +00:00
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,6 +242,7 @@ 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
|
||||||
|
|
||||||
|
if c.section == "functions":
|
||||||
docstring_args += "\n\n Returns:\n "
|
docstring_args += "\n\n Returns:\n "
|
||||||
if c.return_type in core_types:
|
if c.return_type in core_types:
|
||||||
if "int" in c.return_type or c.return_type == "long":
|
if "int" in c.return_type or c.return_type == "long":
|
||||||
@ -258,6 +263,10 @@ def start():
|
|||||||
else:
|
else:
|
||||||
return_type = "List of :obj:`{}`".format(c.return_type.lower())
|
return_type = "List of :obj:`{}`".format(c.return_type.lower())
|
||||||
else:
|
else:
|
||||||
|
if c.section == "functions":
|
||||||
|
try:
|
||||||
|
constructors = by_types[capit(sub_type)]
|
||||||
|
except KeyError:
|
||||||
return_type = "List of :class:`pyrogram.api.types.{}`".format(
|
return_type = "List of :class:`pyrogram.api.types.{}`".format(
|
||||||
".".join(
|
".".join(
|
||||||
sub_type.split(".")[:-1]
|
sub_type.split(".")[:-1]
|
||||||
@ -265,11 +274,41 @@ def start():
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return_type = ":class:`pyrogram.api.types.{}`".format(
|
constructors = ["List of :class:`pyrogram.api.types.{}`".format(
|
||||||
".".join(
|
".".join(
|
||||||
c.return_type.split(".")[:-1]
|
i.split(".")[:-1]
|
||||||
+ [capit(c.return_type.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
|
docstring_args += return_type
|
||||||
|
Loading…
Reference in New Issue
Block a user