From 22c51fdd70b1e501b9707b7eef324c6b06c92ede Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 1 Apr 2018 14:34:29 +0200 Subject: [PATCH] Fix docstrings generation for Pyrogram types --- compiler/api/compiler.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index 3e15a2bd..3d5af589 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -38,7 +38,7 @@ types_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 == "long": return ":obj:`int` :obj:`64-bit`" @@ -58,13 +58,20 @@ def get_docstring_arg_type(t: str, is_list: bool = False): elif t == "!X": return "Any method from :obj:`pyrogram.api.functions`" 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: + if is_pyrogram_type: + t = "pyrogram." + t + t = types_to_constructors.get(t, [t]) + n = len(t) - 1 t = (("e" if is_list else "E") + "ither " if n else "") + ", ".join( - ":obj:`{0} `".format(i) + ":obj:`{1} `".format( + "pyrogram." if is_pyrogram_type else "", + i.lstrip("pyrogram.") + ) for i in t ) @@ -280,7 +287,7 @@ def start(): docstring_args.append( "{} ({}{}):\n {}\n".format( 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 "", re.sub("Optional\. ", "", docs[i].split("ยง")[1].rstrip(".") + ".") )