mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 13:27:47 +00:00
Fix docstrings generation for Pyrogram types
This commit is contained in:
parent
1bbb282dab
commit
22c51fdd70
@ -38,7 +38,7 @@ types_to_functions = {}
|
|||||||
constructors_to_functions = {}
|
constructors_to_functions = {}
|
||||||
|
|
||||||
|
|
||||||
def get_docstring_arg_type(t: str, is_list: bool = False):
|
def get_docstring_arg_type(t: str, is_list: bool = False, is_pyrogram_type: bool = False):
|
||||||
if t in core_types:
|
if t in core_types:
|
||||||
if t == "long":
|
if t == "long":
|
||||||
return ":obj:`int` :obj:`64-bit`"
|
return ":obj:`int` :obj:`64-bit`"
|
||||||
@ -58,13 +58,20 @@ def get_docstring_arg_type(t: str, is_list: bool = False):
|
|||||||
elif t == "!X":
|
elif t == "!X":
|
||||||
return "Any method from :obj:`pyrogram.api.functions`"
|
return "Any method from :obj:`pyrogram.api.functions`"
|
||||||
elif t.startswith("Vector"):
|
elif t.startswith("Vector"):
|
||||||
return "List of " + get_docstring_arg_type(t.split("<")[1][:-1], is_list=True)
|
return "List of " + get_docstring_arg_type(t.split("<", 1)[1][:-1], True, is_pyrogram_type)
|
||||||
else:
|
else:
|
||||||
|
if is_pyrogram_type:
|
||||||
|
t = "pyrogram." + t
|
||||||
|
|
||||||
t = types_to_constructors.get(t, [t])
|
t = types_to_constructors.get(t, [t])
|
||||||
|
|
||||||
n = len(t) - 1
|
n = len(t) - 1
|
||||||
|
|
||||||
t = (("e" if is_list else "E") + "ither " if n else "") + ", ".join(
|
t = (("e" if is_list else "E") + "ither " if n else "") + ", ".join(
|
||||||
":obj:`{0} <pyrogram.api.types.{0}>`".format(i)
|
":obj:`{1} <pyrogram.api.types.{0}{1}>`".format(
|
||||||
|
"pyrogram." if is_pyrogram_type else "",
|
||||||
|
i.lstrip("pyrogram.")
|
||||||
|
)
|
||||||
for i in t
|
for i in t
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -280,7 +287,7 @@ def start():
|
|||||||
docstring_args.append(
|
docstring_args.append(
|
||||||
"{} ({}{}):\n {}\n".format(
|
"{} ({}{}):\n {}\n".format(
|
||||||
arg_name,
|
arg_name,
|
||||||
get_docstring_arg_type(arg_type),
|
get_docstring_arg_type(arg_type, is_pyrogram_type=True),
|
||||||
", optional" if "Optional" in docs[i] else "",
|
", optional" if "Optional" in docs[i] else "",
|
||||||
re.sub("Optional\. ", "", docs[i].split("§")[1].rstrip(".") + ".")
|
re.sub("Optional\. ", "", docs[i].split("§")[1].rstrip(".") + ".")
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user