@@ -94,6 +94,19 @@ def camel(s: str):
9494 return "" .join ([i [0 ].upper () + i [1 :] for i in s .split ("_" )])
9595
9696
97+ # noinspection PyShadowingBuiltins, PyShadowingNames
98+ def get_return_type_hint (qualtype : str ) -> str :
99+ """Get return type hint for generic TLObject"""
100+ if qualtype .startswith ("Vector" ):
101+ # Extract inner type from Vector<Type>
102+ inner = qualtype .split ("<" )[1 ][:- 1 ]
103+ ns , name = inner .split ("." ) if "." in inner else ("" , inner )
104+ return f'"List[raw.base.{ "." .join ([ns , name ]).strip ("." )} ]"'
105+ else :
106+ ns , name = qualtype .split ("." ) if "." in qualtype else ("" , qualtype )
107+ return f'"raw.base.{ "." .join ([ns , name ]).strip ("." )} "'
108+
109+
97110# noinspection PyShadowingBuiltins, PyShadowingNames
98111def get_type_hint (type : str ) -> str :
99112 is_flag = FLAGS_RE .match (type )
@@ -541,6 +554,12 @@ def start(format: bool = False):
541554 slots = ", " .join ([f'"{ i [0 ]} "' for i in sorted_args ])
542555 return_arguments = ", " .join ([f"{ i [0 ]} ={ i [0 ]} " for i in sorted_args ])
543556
557+ # Generate generic type hint for functions
558+ if c .section == "functions" :
559+ generic_type = f"[{ get_return_type_hint (c .qualtype )} ]"
560+ else :
561+ generic_type = ""
562+
544563 compiled_combinator = combinator_tmpl .format (
545564 notice = notice ,
546565 warning = WARNING ,
@@ -553,7 +572,8 @@ def start(format: bool = False):
553572 fields = fields ,
554573 read_types = read_types ,
555574 write_types = write_types ,
556- return_arguments = return_arguments
575+ return_arguments = return_arguments ,
576+ generic_type = generic_type
557577 )
558578
559579 directory = "types" if c .section == "types" else c .section
0 commit comments