mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-31 22:35:36 +00:00
Add core type hints for generated classes
This commit is contained in:
@@ -99,6 +99,32 @@ def get_references(t: str):
|
|||||||
return t
|
return t
|
||||||
|
|
||||||
|
|
||||||
|
def get_argument_type(arg):
|
||||||
|
is_flag = FLAGS_RE.match(arg[1])
|
||||||
|
name, t = arg
|
||||||
|
|
||||||
|
if is_flag:
|
||||||
|
t = t.split("?")[1]
|
||||||
|
|
||||||
|
if t in core_types:
|
||||||
|
if t == "long" or "int" in t:
|
||||||
|
t = ": int"
|
||||||
|
elif t == "double":
|
||||||
|
t = ": float"
|
||||||
|
elif t == "string":
|
||||||
|
t = ": str"
|
||||||
|
else:
|
||||||
|
t = ": {}".format(t.lower())
|
||||||
|
elif t == "true":
|
||||||
|
t = ": bool"
|
||||||
|
elif t.startswith("Vector"):
|
||||||
|
t = ": list"
|
||||||
|
else:
|
||||||
|
return name + ("=None" if is_flag else "")
|
||||||
|
|
||||||
|
return name + t + (" = None" if is_flag else "")
|
||||||
|
|
||||||
|
|
||||||
class Combinator:
|
class Combinator:
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
section: str,
|
section: str,
|
||||||
@@ -263,10 +289,7 @@ def start():
|
|||||||
sorted_args = sort_args(c.args)
|
sorted_args = sort_args(c.args)
|
||||||
|
|
||||||
arguments = ", " + ", ".join(
|
arguments = ", " + ", ".join(
|
||||||
["{}{}".format(
|
[get_argument_type(i) for i in sorted_args]
|
||||||
i[0],
|
|
||||||
"=None" if FLAGS_RE.match(i[1]) else ""
|
|
||||||
) for i in sorted_args]
|
|
||||||
) if c.args else ""
|
) if c.args else ""
|
||||||
|
|
||||||
fields = "\n ".join(
|
fields = "\n ".join(
|
||||||
|
@@ -22,4 +22,7 @@ from .gzip_packed import GzipPacked
|
|||||||
from .message import Message
|
from .message import Message
|
||||||
from .msg_container import MsgContainer
|
from .msg_container import MsgContainer
|
||||||
from .object import Object
|
from .object import Object
|
||||||
from .primitives import *
|
from .primitives import (
|
||||||
|
Bool, BoolTrue, BoolFalse, Bytes, Double,
|
||||||
|
Int, Long, Int128, Int256, Null, String, Vector
|
||||||
|
)
|
||||||
|
Reference in New Issue
Block a user