@@ -135,11 +135,10 @@ def get_type_hint(type: str) -> str:
135135
136136 if is_core :
137137 return f"Optional[{ type } ] = None" if is_flag else type
138- else :
139- ns , name = type .split ("." ) if "." in type else ("" , type )
140- type = '"raw.base.' + "." .join ([ns , name ]).strip ("." ) + '"'
138+ ns , name = type .split ("." ) if "." in type else ("" , type )
139+ type = '"raw.base.' + "." .join ([ns , name ]).strip ("." ) + '"'
141140
142- return f'{ type } { " = None" if is_flag else "" } '
141+ return f'{ type } { " = None" if is_flag else "" } '
143142
144143
145144def sort_args (args ):
@@ -183,7 +182,7 @@ def get_docstring_arg_type(t: str):
183182 return "``bool``"
184183 else :
185184 return f"``{ t .lower ()} ``"
186- elif t == "TLObject" or t == "X" :
185+ elif t in { "TLObject" , "X" } :
187186 return "Any object from :obj:`~hydrogram.raw.types`"
188187 elif t == "!X" :
189188 return "Any function from :obj:`~hydrogram.raw.functions`"
@@ -201,10 +200,7 @@ def get_references(t: str, kind: str):
201200 else :
202201 raise ValueError ("Invalid kind" )
203202
204- if t :
205- return "\n " .join (t ), len (t )
206-
207- return None , 0
203+ return ("\n " .join (t ), len (t )) if t else (None , 0 )
208204
209205
210206# noinspection PyShadowingBuiltins
@@ -225,32 +221,23 @@ def start(format: bool = False):
225221 combinator_tmpl = f2 .read ()
226222
227223 with open (NOTICE_PATH , encoding = "utf-8" ) as f :
228- notice = []
229-
230- for line in f .readlines ():
231- notice .append (f"# { line } " .strip ())
232-
224+ notice = [f"# { line } " .strip () for line in f ]
233225 notice = "\n " .join (notice )
234226
235- section = None
236227 layer = None
237228 combinators = []
238229
230+ section = None
239231 for line in schema :
240- # Check for section changer lines
241- section_match = SECTION_RE .match (line )
242- if section_match :
232+ if section_match := SECTION_RE .match (line ):
243233 section = section_match .group (1 )
244234 continue
245235
246- # Save the layer version
247- layer_match = LAYER_RE .match (line )
248- if layer_match :
236+ if layer_match := LAYER_RE .match (line ):
249237 layer = layer_match .group (1 )
250238 continue
251239
252- combinator_match = COMBINATOR_RE .match (line )
253- if combinator_match :
240+ if combinator_match := COMBINATOR_RE .match (line ):
254241 # noinspection PyShadowingBuiltins
255242 qualname , id , qualtype = combinator_match .groups ()
256243
@@ -350,14 +337,7 @@ def start(format: bool = False):
350337 references , ref_count = get_references (qualtype , "types" )
351338
352339 if references :
353- docstring += (
354- f"\n \n Functions:\n This object can be returned by "
355- f"{ ref_count } function{ 's' if ref_count > 1 else '' } .\n \n "
356- f" .. currentmodule:: hydrogram.raw.functions\n \n "
357- f" .. autosummary::\n "
358- f" :nosignatures:\n \n "
359- f" " + references
360- )
340+ docstring += f"\n \n Functions:\n This object can be returned by { ref_count } function{ 's' if ref_count > 1 else '' } .\n \n .. currentmodule:: hydrogram.raw.functions\n \n .. autosummary::\n :nosignatures:\n \n { references } "
361341
362342 with open (dir_path / f"{ snake (module )} .py" , "w" ) as f :
363343 f .write (
@@ -392,7 +372,7 @@ def start(format: bool = False):
392372
393373 combinator_docs = docs ["method" ] if c .section == "functions" else docs ["constructor" ]
394374
395- for i , arg in enumerate ( sorted_args ) :
375+ for arg in sorted_args :
396376 arg_name , arg_type = arg
397377 is_optional = FLAGS_RE .match (arg_type )
398378 arg_type = arg_type .split ("?" )[- 1 ]
@@ -402,31 +382,21 @@ def start(format: bool = False):
402382 arg_docs = arg_docs ["params" ].get (arg_name , "N/A" ) if arg_docs else "N/A"
403383
404384 docstring_args .append (
405- "{} ({}{}):\n {}\n " .format (
406- arg_name ,
407- get_docstring_arg_type (arg_type ),
408- ", *optional*" if is_optional else "" ,
409- arg_docs ,
410- )
385+ f'{ arg_name } ({ get_docstring_arg_type (arg_type )} { ", *optional*" if is_optional else "" } ):\n { arg_docs } \n '
411386 )
412387
413388 if c .section == "types" :
414389 constructor_docs = docs ["constructor" ].get (c .qualname , None )
415390
416- if constructor_docs :
417- constructor_docs = constructor_docs ["desc" ]
418- else :
419- constructor_docs = "Telegram API type."
420-
391+ constructor_docs = (
392+ constructor_docs ["desc" ] if constructor_docs else "Telegram API type."
393+ )
421394 docstring += constructor_docs + "\n "
422395 docstring += f"\n Constructor of :obj:`~hydrogram.raw.base.{ c .qualtype } `."
396+ elif function_docs := docs ["method" ].get (c .qualname , None ):
397+ docstring += function_docs ["desc" ] + "\n "
423398 else :
424- function_docs = docs ["method" ].get (c .qualname , None )
425-
426- if function_docs :
427- docstring += function_docs ["desc" ] + "\n "
428- else :
429- docstring += "Telegram API function."
399+ docstring += "Telegram API function."
430400
431401 docstring += f"\n \n Details:\n - Layer: ``{ layer } ``\n - ID: ``{ c .id [2 :].upper ()} ``\n \n "
432402 docstring += " Parameters:\n " + (
@@ -439,14 +409,7 @@ def start(format: bool = False):
439409 references , count = get_references (c .qualname , "constructors" )
440410
441411 if references :
442- docstring += (
443- f"\n Functions:\n This object can be returned by "
444- f"{ count } function{ 's' if count > 1 else '' } .\n \n "
445- f" .. currentmodule:: hydrogram.raw.functions\n \n "
446- f" .. autosummary::\n "
447- f" :nosignatures:\n \n "
448- f" " + references
449- )
412+ docstring += f"\n Functions:\n This object can be returned by { count } function{ 's' if count > 1 else '' } .\n \n .. currentmodule:: hydrogram.raw.functions\n \n .. autosummary::\n :nosignatures:\n \n { references } "
450413
451414 write_types = read_types = "" if c .has_flags else "# No flags\n "
452415
@@ -503,20 +466,10 @@ def start(format: bool = False):
503466
504467 write_types += "\n "
505468 write_types += f"if self.{ arg_name } is not None:\n "
506- write_types += "b.write(Vector(self.{}{}))\n " .format (
507- arg_name ,
508- f", { sub_type .title ()} " if sub_type in CORE_TYPES else "" ,
509- )
469+ write_types += f'b.write(Vector(self.{ arg_name } { f", { sub_type .title ()} " if sub_type in CORE_TYPES else "" } ))\n '
510470
511471 read_types += "\n "
512- read_types += (
513- "{} = TLObject.read(b{}) if flags{} & (1 << {}) else []\n " .format (
514- arg_name ,
515- f", { sub_type .title ()} " if sub_type in CORE_TYPES else "" ,
516- number ,
517- index ,
518- )
519- )
472+ read_types += f'{ arg_name } = TLObject.read(b{ f", { sub_type .title ()} " if sub_type in CORE_TYPES else "" } ) if flags{ number } & (1 << { index } ) else []\n '
520473 else :
521474 write_types += "\n "
522475 write_types += f"if self.{ arg_name } is not None:\n "
@@ -525,28 +478,20 @@ def start(format: bool = False):
525478 read_types += "\n "
526479 read_types += f"{ arg_name } = TLObject.read(b) if flags{ number } & (1 << { index } ) else None\n "
527480 else :
481+ write_types += "\n "
528482 if arg_type in CORE_TYPES :
529- write_types += "\n "
530483 write_types += f"b.write({ arg_type .title ()} (self.{ arg_name } ))\n "
531484
532485 read_types += "\n "
533486 read_types += f"{ arg_name } = { arg_type .title ()} .read(b)\n "
534487 elif "vector" in arg_type .lower ():
535488 sub_type = arg_type .split ("<" )[1 ][:- 1 ]
536489
537- write_types += "\n "
538- write_types += "b.write(Vector(self.{}{}))\n " .format (
539- arg_name ,
540- f", { sub_type .title ()} " if sub_type in CORE_TYPES else "" ,
541- )
490+ write_types += f'b.write(Vector(self.{ arg_name } { f", { sub_type .title ()} " if sub_type in CORE_TYPES else "" } ))\n '
542491
543492 read_types += "\n "
544- read_types += "{} = TLObject.read(b{})\n " .format (
545- arg_name ,
546- f", { sub_type .title ()} " if sub_type in CORE_TYPES else "" ,
547- )
493+ read_types += f'{ arg_name } = TLObject.read(b{ f", { sub_type .title ()} " if sub_type in CORE_TYPES else "" } )\n '
548494 else :
549- write_types += "\n "
550495 write_types += f"b.write(self.{ arg_name } .write())\n "
551496
552497 read_types += "\n "
0 commit comments