Skip to content

Commit 7c2c878

Browse files
committed
Add core type hints for generated classes
1 parent 3a4e24e commit 7c2c878

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

compiler/api/compiler.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,32 @@ def get_references(t: str):
9999
return t
100100

101101

102+
def get_argument_type(arg):
103+
is_flag = FLAGS_RE.match(arg[1])
104+
name, t = arg
105+
106+
if is_flag:
107+
t = t.split("?")[1]
108+
109+
if t in core_types:
110+
if t == "long" or "int" in t:
111+
t = ": int"
112+
elif t == "double":
113+
t = ": float"
114+
elif t == "string":
115+
t = ": str"
116+
else:
117+
t = ": {}".format(t.lower())
118+
elif t == "true":
119+
t = ": bool"
120+
elif t.startswith("Vector"):
121+
t = ": list"
122+
else:
123+
return name + ("=None" if is_flag else "")
124+
125+
return name + t + (" = None" if is_flag else "")
126+
127+
102128
class Combinator:
103129
def __init__(self,
104130
section: str,
@@ -263,10 +289,7 @@ def start():
263289
sorted_args = sort_args(c.args)
264290

265291
arguments = ", " + ", ".join(
266-
["{}{}".format(
267-
i[0],
268-
"=None" if FLAGS_RE.match(i[1]) else ""
269-
) for i in sorted_args]
292+
[get_argument_type(i) for i in sorted_args]
270293
) if c.args else ""
271294

272295
fields = "\n ".join(

pyrogram/api/core/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@
2222
from .message import Message
2323
from .msg_container import MsgContainer
2424
from .object import Object
25-
from .primitives import *
25+
from .primitives import (
26+
Bool, BoolTrue, BoolFalse, Bytes, Double,
27+
Int, Long, Int128, Int256, Null, String, Vector
28+
)

0 commit comments

Comments
 (0)