FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

style: ruff format the whole code · TechyCSR/hydrogram@1185ac1 · GitHub

style: ruff format the whole code · TechyCSR/hydrogram@1185ac1 · GitHub
Skip to content

Navigation Menu

Commit 1185ac1

Browse files
style: ruff format the whole code
1 parent 34a1a84 commit 1185ac1

324 files changed

Lines changed: 4331 additions & 3229 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎compiler/api/compiler.py‎

Lines changed: 109 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,26 @@
3434

3535
SECTION_RE = re.compile(r"---(\w+)---")
3636
LAYER_RE = re.compile(r"//\sLAYER\s(\d+)")
37-
COMBINATOR_RE = re.compile(r"^([\w.]+)#([0-9a-f]+)\s(?:.*)=\s([\w<>.]+);$", re.MULTILINE)
37+
COMBINATOR_RE = re.compile(
38+
r"^([\w.]+)#([0-9a-f]+)\s(?:.*)=\s([\w<>.]+);$", re.MULTILINE
39+
)
3840
ARGS_RE = re.compile(r"[^{](\w+):([\w?!.<>#]+)")
3941
FLAGS_RE = re.compile(r"flags(\d?)\.(\d+)\?")
4042
FLAGS_RE_2 = re.compile(r"flags(\d?)\.(\d+)\?([\w<>.]+)")
4143
FLAGS_RE_3 = re.compile(r"flags(\d?):#")
4244
INT_RE = re.compile(r"int(\d+)")
4345

44-
CORE_TYPES = ["int", "long", "int128", "int256", "double", "bytes", "string", "Bool", "true"]
46+
CORE_TYPES = [
47+
"int",
48+
"long",
49+
"int128",
50+
"int256",
51+
"double",
52+
"bytes",
53+
"string",
54+
"Bool",
55+
"true",
56+
]
4557

4658
WARNING = """
4759
# # # # # # # # # # # # # # # # # # # # # # # #
@@ -65,11 +77,7 @@
6577
with open("docs.json") as f:
6678
docs = json.load(f)
6779
except FileNotFoundError:
68-
docs = {
69-
"type": {},
70-
"constructor": {},
71-
"method": {}
72-
}
80+
docs = {"type": {}, "constructor": {}, "method": {}}
7381

7482

7583
class Combinator(NamedTuple):
@@ -206,13 +214,14 @@ def start(format: bool = False):
206214
shutil.rmtree(DESTINATION_PATH / "functions", ignore_errors=True)
207215
shutil.rmtree(DESTINATION_PATH / "base", ignore_errors=True)
208216

209-
with open(HOME_PATH / "source/auth_key.tl") as f1, \
210-
open(HOME_PATH / "source/sys_msgs.tl") as f2, \
211-
open(HOME_PATH / "source/main_api.tl") as f3:
217+
with open(HOME_PATH / "source/auth_key.tl") as f1, open(
218+
HOME_PATH / "source/sys_msgs.tl"
219+
) as f2, open(HOME_PATH / "source/main_api.tl") as f3:
212220
schema = (f1.read() + f2.read() + f3.read()).splitlines()
213221

214-
with open(HOME_PATH / "template/type.txt") as f1, \
215-
open(HOME_PATH / "template/combinator.txt") as f2:
222+
with open(HOME_PATH / "template/type.txt") as f1, open(
223+
HOME_PATH / "template/combinator.txt"
224+
) as f2:
216225
type_tmpl = f1.read()
217226
combinator_tmpl = f2.read()
218227

@@ -274,7 +283,7 @@ def start(format: bool = False):
274283
args=args,
275284
qualtype=qualtype,
276285
typespace=typespace,
277-
type=type
286+
type=type,
278287
)
279288

280289
combinators.append(combinator)
@@ -335,22 +344,26 @@ def start(format: bool = False):
335344

336345
docstring = type_docs
337346

338-
docstring += f"\n\n Constructors:\n" \
339-
f" This base type has {constr_count} constructor{'s' if constr_count > 1 else ''} available.\n\n" \
340-
f" .. currentmodule:: hydrogram.raw.types\n\n" \
341-
f" .. autosummary::\n" \
342-
f" :nosignatures:\n\n" \
343-
f" {items}"
347+
docstring += (
348+
f"\n\n Constructors:\n"
349+
f" This base type has {constr_count} constructor{'s' if constr_count > 1 else ''} available.\n\n"
350+
f" .. currentmodule:: hydrogram.raw.types\n\n"
351+
f" .. autosummary::\n"
352+
f" :nosignatures:\n\n"
353+
f" {items}"
354+
)
344355

345356
references, ref_count = get_references(qualtype, "types")
346357

347358
if references:
348-
docstring += f"\n\n Functions:\n This object can be returned by " \
349-
f"{ref_count} function{'s' if ref_count > 1 else ''}.\n\n" \
350-
f" .. currentmodule:: hydrogram.raw.functions\n\n" \
351-
f" .. autosummary::\n" \
352-
f" :nosignatures:\n\n" \
353-
f" " + references
359+
docstring += (
360+
f"\n\n Functions:\n This object can be returned by "
361+
f"{ref_count} function{'s' if ref_count > 1 else ''}.\n\n"
362+
f" .. currentmodule:: hydrogram.raw.functions\n\n"
363+
f" .. autosummary::\n"
364+
f" :nosignatures:\n\n"
365+
f" " + references
366+
)
354367

355368
with open(dir_path / f"{snake(module)}.py", "w") as f:
356369
f.write(
@@ -361,25 +374,24 @@ def start(format: bool = False):
361374
name=type,
362375
qualname=qualtype,
363376
types=", ".join([f"raw.types.{c}" for c in constructors]),
364-
doc_name=snake(type).replace("_", "-")
377+
doc_name=snake(type).replace("_", "-"),
365378
)
366379
)
367380

368381
for c in combinators:
369382
sorted_args = sort_args(c.args)
370383

371-
arguments = (
372-
(", *, " if c.args else "") +
373-
(", ".join(
374-
[f"{i[0]}: {get_type_hint(i[1])}"
375-
for i in sorted_args]
376-
) if sorted_args else "")
384+
arguments = (", *, " if c.args else "") + (
385+
", ".join([f"{i[0]}: {get_type_hint(i[1])}" for i in sorted_args])
386+
if sorted_args
387+
else ""
377388
)
378389

379-
fields = "\n ".join(
380-
[f"self.{i[0]} = {i[0]} # {i[1]}"
381-
for i in sorted_args]
382-
) if sorted_args else "pass"
390+
fields = (
391+
"\n ".join([f"self.{i[0]} = {i[0]} # {i[1]}" for i in sorted_args])
392+
if sorted_args
393+
else "pass"
394+
)
383395

384396
docstring = ""
385397
docstring_args = []
@@ -407,7 +419,7 @@ def start(format: bool = False):
407419
arg_name,
408420
get_docstring_arg_type(arg_type),
409421
", *optional*".format(flag_number) if is_optional else "",
410-
arg_docs
422+
arg_docs,
411423
)
412424
)
413425

@@ -420,7 +432,9 @@ def start(format: bool = False):
420432
constructor_docs = "Telegram API type."
421433

422434
docstring += constructor_docs + "\n"
423-
docstring += f"\n Constructor of :obj:`~hydrogram.raw.base.{c.qualtype}`."
435+
docstring += (
436+
f"\n Constructor of :obj:`~hydrogram.raw.base.{c.qualtype}`."
437+
)
424438
else:
425439
function_docs = docs["method"].get(c.qualname, None)
426440

@@ -430,21 +444,26 @@ def start(format: bool = False):
430444
docstring += f"Telegram API function."
431445

432446
docstring += f"\n\n Details:\n - Layer: ``{layer}``\n - ID: ``{c.id[2:].upper()}``\n\n"
433-
docstring += f" Parameters:\n " + \
434-
(f"\n ".join(docstring_args) if docstring_args else "No parameters required.\n")
447+
docstring += f" Parameters:\n " + (
448+
f"\n ".join(docstring_args)
449+
if docstring_args
450+
else "No parameters required.\n"
451+
)
435452

436453
if c.section == "functions":
437454
docstring += "\n Returns:\n " + get_docstring_arg_type(c.qualtype)
438455
else:
439456
references, count = get_references(c.qualname, "constructors")
440457

441458
if references:
442-
docstring += f"\n Functions:\n This object can be returned by " \
443-
f"{count} function{'s' if count > 1 else ''}.\n\n" \
444-
f" .. currentmodule:: hydrogram.raw.functions\n\n" \
445-
f" .. autosummary::\n" \
446-
f" :nosignatures:\n\n" \
447-
f" " + references
459+
docstring += (
460+
f"\n Functions:\n This object can be returned by "
461+
f"{count} function{'s' if count > 1 else ''}.\n\n"
462+
f" .. currentmodule:: hydrogram.raw.functions\n\n"
463+
f" .. autosummary::\n"
464+
f" :nosignatures:\n\n"
465+
f" " + references
466+
)
448467

449468
write_types = read_types = "" if c.has_flags else "# No flags\n "
450469

@@ -461,17 +480,24 @@ def start(format: bool = False):
461480
if arg_name != f"flags{flag.group(1)}":
462481
continue
463482

464-
if flag.group(3) == "true" or flag.group(3).startswith("Vector"):
465-
write_flags.append(f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} else 0")
483+
if flag.group(3) == "true" or flag.group(3).startswith(
484+
"Vector"
485+
):
486+
write_flags.append(
487+
f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} else 0"
488+
)
466489
else:
467490
write_flags.append(
468-
f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} is not None else 0")
469-
470-
write_flags = "\n ".join([
471-
f"{arg_name} = 0",
472-
"\n ".join(write_flags),
473-
f"b.write(Int({arg_name}))\n "
474-
])
491+
f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} is not None else 0"
492+
)
493+
494+
write_flags = "\n ".join(
495+
[
496+
f"{arg_name} = 0",
497+
"\n ".join(write_flags),
498+
f"b.write(Int({arg_name}))\n ",
499+
]
500+
)
475501

476502
write_types += write_flags
477503
read_types += f"\n {arg_name} = Int.read(b)\n "
@@ -487,7 +513,9 @@ def start(format: bool = False):
487513
elif flag_type in CORE_TYPES:
488514
write_types += "\n "
489515
write_types += f"if self.{arg_name} is not None:\n "
490-
write_types += f"b.write({flag_type.title()}(self.{arg_name}))\n "
516+
write_types += (
517+
f"b.write({flag_type.title()}(self.{arg_name}))\n "
518+
)
491519

492520
read_types += "\n "
493521
read_types += f"{arg_name} = {flag_type.title()}.read(b) if flags{number} & (1 << {index}) else None"
@@ -497,12 +525,16 @@ def start(format: bool = False):
497525
write_types += "\n "
498526
write_types += f"if self.{arg_name} is not None:\n "
499527
write_types += "b.write(Vector(self.{}{}))\n ".format(
500-
arg_name, f", {sub_type.title()}" if sub_type in CORE_TYPES else ""
528+
arg_name,
529+
f", {sub_type.title()}" if sub_type in CORE_TYPES else "",
501530
)
502531

503532
read_types += "\n "
504533
read_types += "{} = TLObject.read(b{}) if flags{} & (1 << {}) else []\n ".format(
505-
arg_name, f", {sub_type.title()}" if sub_type in CORE_TYPES else "", number, index
534+
arg_name,
535+
f", {sub_type.title()}" if sub_type in CORE_TYPES else "",
536+
number,
537+
index,
506538
)
507539
else:
508540
write_types += "\n "
@@ -514,7 +546,9 @@ def start(format: bool = False):
514546
else:
515547
if arg_type in CORE_TYPES:
516548
write_types += "\n "
517-
write_types += f"b.write({arg_type.title()}(self.{arg_name}))\n "
549+
write_types += (
550+
f"b.write({arg_type.title()}(self.{arg_name}))\n "
551+
)
518552

519553
read_types += "\n "
520554
read_types += f"{arg_name} = {arg_type.title()}.read(b)\n "
@@ -523,12 +557,14 @@ def start(format: bool = False):
523557

524558
write_types += "\n "
525559
write_types += "b.write(Vector(self.{}{}))\n ".format(
526-
arg_name, f", {sub_type.title()}" if sub_type in CORE_TYPES else ""
560+
arg_name,
561+
f", {sub_type.title()}" if sub_type in CORE_TYPES else "",
527562
)
528563

529564
read_types += "\n "
530565
read_types += "{} = TLObject.read(b{})\n ".format(
531-
arg_name, f", {sub_type.title()}" if sub_type in CORE_TYPES else ""
566+
arg_name,
567+
f", {sub_type.title()}" if sub_type in CORE_TYPES else "",
532568
)
533569
else:
534570
write_types += "\n "
@@ -552,7 +588,7 @@ def start(format: bool = False):
552588
fields=fields,
553589
read_types=read_types,
554590
write_types=write_types,
555-
return_arguments=return_arguments
591+
return_arguments=return_arguments,
556592
)
557593

558594
directory = "types" if c.section == "types" else c.section
@@ -569,7 +605,11 @@ def start(format: bool = False):
569605
with open(dir_path / f"{snake(module)}.py", "w") as f:
570606
f.write(compiled_combinator)
571607

572-
d = namespaces_to_constructors if c.section == "types" else namespaces_to_functions
608+
d = (
609+
namespaces_to_constructors
610+
if c.section == "types"
611+
else namespaces_to_functions
612+
)
573613

574614
if c.namespace not in d:
575615
d[c.namespace] = []
@@ -606,7 +646,9 @@ def start(format: bool = False):
606646
f.write(f"from .{snake(module)} import {t}\n")
607647

608648
if not namespace:
609-
f.write(f"from . import {', '.join(filter(bool, namespaces_to_constructors))}\n")
649+
f.write(
650+
f"from . import {', '.join(filter(bool, namespaces_to_constructors))}\n"
651+
)
610652

611653
for namespace, types in namespaces_to_functions.items():
612654
with open(DESTINATION_PATH / "functions" / namespace / "__init__.py", "w") as f:
@@ -622,7 +664,9 @@ def start(format: bool = False):
622664
f.write(f"from .{snake(module)} import {t}\n")
623665

624666
if not namespace:
625-
f.write(f"from . import {', '.join(filter(bool, namespaces_to_functions))}")
667+
f.write(
668+
f"from . import {', '.join(filter(bool, namespaces_to_functions))}"
669+
)
626670

627671
with open(DESTINATION_PATH / "all.py", "w", encoding="utf-8") as f:
628672
f.write(notice + "\n\n")

0 commit comments

Comments
 (0)

Footer

© 2026 GitHub, Inc.

Back | FazBrowse Home | New Git URL