Skip to content

Commit ee8b8d5

Browse files
committed
black code format
1 parent de9065f commit ee8b8d5

File tree

425 files changed

+5503
-4255
lines changed

Some content is hidden

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

425 files changed

+5503
-4255
lines changed

compiler/api/compiler.py

Lines changed: 106 additions & 64 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

@@ -277,7 +286,7 @@ def start(format: bool = False):
277286
args=args,
278287
qualtype=qualtype,
279288
typespace=typespace,
280-
type=type
289+
type=type,
281290
)
282291

283292
combinators.append(combinator)
@@ -338,22 +347,26 @@ def start(format: bool = False):
338347

339348
docstring = type_docs
340349

341-
docstring += f"\n\n Constructors:\n" \
342-
f" This base type has {constr_count} constructor{'s' if constr_count > 1 else ''} available.\n\n" \
343-
f" .. currentmodule:: pyrogram.raw.types\n\n" \
344-
f" .. autosummary::\n" \
345-
f" :nosignatures:\n\n" \
346-
f" {items}"
350+
docstring += (
351+
f"\n\n Constructors:\n"
352+
f" This base type has {constr_count} constructor{'s' if constr_count > 1 else ''} available.\n\n"
353+
f" .. currentmodule:: pyrogram.raw.types\n\n"
354+
f" .. autosummary::\n"
355+
f" :nosignatures:\n\n"
356+
f" {items}"
357+
)
347358

348359
references, ref_count = get_references(qualtype, "types")
349360

350361
if references:
351-
docstring += f"\n\n Functions:\n This object can be returned by " \
352-
f"{ref_count} function{'s' if ref_count > 1 else ''}.\n\n" \
353-
f" .. currentmodule:: pyrogram.raw.functions\n\n" \
354-
f" .. autosummary::\n" \
355-
f" :nosignatures:\n\n" \
356-
f" " + references
362+
docstring += (
363+
f"\n\n Functions:\n This object can be returned by "
364+
f"{ref_count} function{'s' if ref_count > 1 else ''}.\n\n"
365+
f" .. currentmodule:: pyrogram.raw.functions\n\n"
366+
f" .. autosummary::\n"
367+
f" :nosignatures:\n\n"
368+
f" " + references
369+
)
357370

358371
with open(dir_path / f"{snake(module)}.py", "w") as f:
359372
f.write(
@@ -364,25 +377,24 @@ def start(format: bool = False):
364377
name=type,
365378
qualname=qualtype,
366379
types=", ".join([f"raw.types.{c}" for c in constructors]),
367-
doc_name=snake(type).replace("_", "-")
380+
doc_name=snake(type).replace("_", "-"),
368381
)
369382
)
370383

371384
for c in combinators:
372385
sorted_args = sort_args(c.args)
373386

374-
arguments = (
375-
(", *, " if c.args else "") +
376-
(", ".join(
377-
[f"{i[0]}: {get_type_hint(i[1])}"
378-
for i in sorted_args]
379-
) if sorted_args else "")
387+
arguments = (", *, " if c.args else "") + (
388+
", ".join([f"{i[0]}: {get_type_hint(i[1])}" for i in sorted_args])
389+
if sorted_args
390+
else ""
380391
)
381392

382-
fields = "\n ".join(
383-
[f"self.{i[0]} = {i[0]} # {i[1]}"
384-
for i in sorted_args]
385-
) if sorted_args else "pass"
393+
fields = (
394+
"\n ".join([f"self.{i[0]} = {i[0]} # {i[1]}" for i in sorted_args])
395+
if sorted_args
396+
else "pass"
397+
)
386398

387399
docstring = ""
388400
docstring_args = []
@@ -410,7 +422,7 @@ def start(format: bool = False):
410422
arg_name,
411423
get_docstring_arg_type(arg_type),
412424
", *optional*".format(flag_number) if is_optional else "",
413-
arg_docs
425+
arg_docs,
414426
)
415427
)
416428

@@ -433,21 +445,26 @@ def start(format: bool = False):
433445
docstring += f"Telegram API function."
434446

435447
docstring += f"\n\n Details:\n - Layer: ``{layer}``\n - ID: ``{c.id[2:].upper()}``\n\n"
436-
docstring += f" Parameters:\n " + \
437-
(f"\n ".join(docstring_args) if docstring_args else "No parameters required.\n")
448+
docstring += f" Parameters:\n " + (
449+
f"\n ".join(docstring_args)
450+
if docstring_args
451+
else "No parameters required.\n"
452+
)
438453

439454
if c.section == "functions":
440455
docstring += "\n Returns:\n " + get_docstring_arg_type(c.qualtype)
441456
else:
442457
references, count = get_references(c.qualname, "constructors")
443458

444459
if references:
445-
docstring += f"\n Functions:\n This object can be returned by " \
446-
f"{count} function{'s' if count > 1 else ''}.\n\n" \
447-
f" .. currentmodule:: pyrogram.raw.functions\n\n" \
448-
f" .. autosummary::\n" \
449-
f" :nosignatures:\n\n" \
450-
f" " + references
460+
docstring += (
461+
f"\n Functions:\n This object can be returned by "
462+
f"{count} function{'s' if count > 1 else ''}.\n\n"
463+
f" .. currentmodule:: pyrogram.raw.functions\n\n"
464+
f" .. autosummary::\n"
465+
f" :nosignatures:\n\n"
466+
f" " + references
467+
)
451468

452469
write_types = read_types = "" if c.has_flags else "# No flags\n "
453470

@@ -464,17 +481,24 @@ def start(format: bool = False):
464481
if arg_name != f"flags{flag.group(1)}":
465482
continue
466483

467-
if flag.group(3) == "true" or flag.group(3).startswith("Vector"):
468-
write_flags.append(f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} else 0")
484+
if flag.group(3) == "true" or flag.group(3).startswith(
485+
"Vector"
486+
):
487+
write_flags.append(
488+
f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} else 0"
489+
)
469490
else:
470491
write_flags.append(
471-
f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} is not None else 0")
472-
473-
write_flags = "\n ".join([
474-
f"{arg_name} = 0",
475-
"\n ".join(write_flags),
476-
f"b.write(Int({arg_name}))\n "
477-
])
492+
f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} is not None else 0"
493+
)
494+
495+
write_flags = "\n ".join(
496+
[
497+
f"{arg_name} = 0",
498+
"\n ".join(write_flags),
499+
f"b.write(Int({arg_name}))\n ",
500+
]
501+
)
478502

479503
write_types += write_flags
480504
read_types += f"\n {arg_name} = Int.read(b)\n "
@@ -490,7 +514,9 @@ def start(format: bool = False):
490514
elif flag_type in CORE_TYPES:
491515
write_types += "\n "
492516
write_types += f"if self.{arg_name} is not None:\n "
493-
write_types += f"b.write({flag_type.title()}(self.{arg_name}))\n "
517+
write_types += (
518+
f"b.write({flag_type.title()}(self.{arg_name}))\n "
519+
)
494520

495521
read_types += "\n "
496522
read_types += f"{arg_name} = {flag_type.title()}.read(b) if flags{number} & (1 << {index}) else None"
@@ -500,12 +526,16 @@ def start(format: bool = False):
500526
write_types += "\n "
501527
write_types += f"if self.{arg_name} is not None:\n "
502528
write_types += "b.write(Vector(self.{}{}))\n ".format(
503-
arg_name, f", {sub_type.title()}" if sub_type in CORE_TYPES else ""
529+
arg_name,
530+
f", {sub_type.title()}" if sub_type in CORE_TYPES else "",
504531
)
505532

506533
read_types += "\n "
507534
read_types += "{} = TLObject.read(b{}) if flags{} & (1 << {}) else []\n ".format(
508-
arg_name, f", {sub_type.title()}" if sub_type in CORE_TYPES else "", number, index
535+
arg_name,
536+
f", {sub_type.title()}" if sub_type in CORE_TYPES else "",
537+
number,
538+
index,
509539
)
510540
else:
511541
write_types += "\n "
@@ -517,7 +547,9 @@ def start(format: bool = False):
517547
else:
518548
if arg_type in CORE_TYPES:
519549
write_types += "\n "
520-
write_types += f"b.write({arg_type.title()}(self.{arg_name}))\n "
550+
write_types += (
551+
f"b.write({arg_type.title()}(self.{arg_name}))\n "
552+
)
521553

522554
read_types += "\n "
523555
read_types += f"{arg_name} = {arg_type.title()}.read(b)\n "
@@ -526,12 +558,14 @@ def start(format: bool = False):
526558

527559
write_types += "\n "
528560
write_types += "b.write(Vector(self.{}{}))\n ".format(
529-
arg_name, f", {sub_type.title()}" if sub_type in CORE_TYPES else ""
561+
arg_name,
562+
f", {sub_type.title()}" if sub_type in CORE_TYPES else "",
530563
)
531564

532565
read_types += "\n "
533566
read_types += "{} = TLObject.read(b{})\n ".format(
534-
arg_name, f", {sub_type.title()}" if sub_type in CORE_TYPES else ""
567+
arg_name,
568+
f", {sub_type.title()}" if sub_type in CORE_TYPES else "",
535569
)
536570
else:
537571
write_types += "\n "
@@ -555,7 +589,7 @@ def start(format: bool = False):
555589
fields=fields,
556590
read_types=read_types,
557591
write_types=write_types,
558-
return_arguments=return_arguments
592+
return_arguments=return_arguments,
559593
)
560594

561595
directory = "types" if c.section == "types" else c.section
@@ -572,7 +606,11 @@ def start(format: bool = False):
572606
with open(dir_path / f"{snake(module)}.py", "w") as f:
573607
f.write(compiled_combinator)
574608

575-
d = namespaces_to_constructors if c.section == "types" else namespaces_to_functions
609+
d = (
610+
namespaces_to_constructors
611+
if c.section == "types"
612+
else namespaces_to_functions
613+
)
576614

577615
if c.namespace not in d:
578616
d[c.namespace] = []
@@ -609,7 +647,9 @@ def start(format: bool = False):
609647
f.write(f"from .{snake(module)} import {t}\n")
610648

611649
if not namespace:
612-
f.write(f"from . import {', '.join(filter(bool, namespaces_to_constructors))}\n")
650+
f.write(
651+
f"from . import {', '.join(filter(bool, namespaces_to_constructors))}\n"
652+
)
613653

614654
for namespace, types in namespaces_to_functions.items():
615655
with open(DESTINATION_PATH / "functions" / namespace / "__init__.py", "w") as f:
@@ -625,7 +665,9 @@ def start(format: bool = False):
625665
f.write(f"from .{snake(module)} import {t}\n")
626666

627667
if not namespace:
628-
f.write(f"from . import {', '.join(filter(bool, namespaces_to_functions))}")
668+
f.write(
669+
f"from . import {', '.join(filter(bool, namespaces_to_functions))}"
670+
)
629671

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

compiler/errors/compiler.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,22 @@ def start():
7373
with open(init, "a", encoding="utf-8") as f_init:
7474
f_init.write("from .{}_{} import *\n".format(name.lower(), code))
7575

76-
with open("{}/source/{}".format(HOME, i), encoding="utf-8") as f_csv, \
77-
open("{}/{}_{}.py".format(DEST, name.lower(), code), "w", encoding="utf-8") as f_class:
76+
with open("{}/source/{}".format(HOME, i), encoding="utf-8") as f_csv, open(
77+
"{}/{}_{}.py".format(DEST, name.lower(), code), "w", encoding="utf-8"
78+
) as f_class:
7879
reader = csv.reader(f_csv, delimiter="\t")
7980

8081
super_class = caml(name)
81-
name = " ".join([str(i.capitalize()) for i in re.sub(r"_", " ", name).lower().split(" ")])
82+
name = " ".join(
83+
[
84+
str(i.capitalize())
85+
for i in re.sub(r"_", " ", name).lower().split(" ")
86+
]
87+
)
8288

8389
sub_classes = []
8490

85-
f_all.write(" \"_\": \"{}\",\n".format(super_class))
91+
f_all.write(' "_": "{}",\n'.format(super_class))
8692

8793
for j, row in enumerate(reader):
8894
if j == 0:
@@ -99,27 +105,36 @@ def start():
99105
sub_class = re.sub(r"^2", "Two", sub_class)
100106
sub_class = re.sub(r" ", "", sub_class)
101107

102-
f_all.write(" \"{}\": \"{}\",\n".format(error_id, sub_class))
108+
f_all.write(' "{}": "{}",\n'.format(error_id, sub_class))
103109

104110
sub_classes.append((sub_class, error_id, error_message))
105111

106-
with open("{}/template/class.txt".format(HOME), "r", encoding="utf-8") as f_class_template:
112+
with open(
113+
"{}/template/class.txt".format(HOME), "r", encoding="utf-8"
114+
) as f_class_template:
107115
class_template = f_class_template.read()
108116

109-
with open("{}/template/sub_class.txt".format(HOME), "r", encoding="utf-8") as f_sub_class_template:
117+
with open(
118+
"{}/template/sub_class.txt".format(HOME), "r", encoding="utf-8"
119+
) as f_sub_class_template:
110120
sub_class_template = f_sub_class_template.read()
111121

112122
class_template = class_template.format(
113123
notice=notice,
114124
super_class=super_class,
115125
code=code,
116126
docstring='"""{}"""'.format(name),
117-
sub_classes="".join([sub_class_template.format(
118-
sub_class=k[0],
119-
super_class=super_class,
120-
id="\"{}\"".format(k[1]),
121-
docstring='"""{}"""'.format(k[2])
122-
) for k in sub_classes])
127+
sub_classes="".join(
128+
[
129+
sub_class_template.format(
130+
sub_class=k[0],
131+
super_class=super_class,
132+
id='"{}"'.format(k[1]),
133+
docstring='"""{}"""'.format(k[2]),
134+
)
135+
for k in sub_classes
136+
]
137+
),
123138
)
124139

125140
f_class.write(class_template)

0 commit comments

Comments
 (0)