Skip to content

Commit 1dafa3e

Browse files
committed
Format code using Black with 120 as max line length
1 parent a4ea3f7 commit 1dafa3e

175 files changed

Lines changed: 3765 additions & 3694 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: 46 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ def get_docstring_arg_type(t: str, is_list: bool = False, is_pyrogram_type: bool
6868

6969
t = (("e" if is_list else "E") + "ither " if n else "") + ", ".join(
7070
":obj:`{1} <{0}.{1}>`".format(
71-
"pyrogram.types" if is_pyrogram_type else "pyrogram.api.types",
72-
i.replace("pyrogram.", "")
71+
"pyrogram.types" if is_pyrogram_type else "pyrogram.api.types", i.replace("pyrogram.", "")
7372
)
7473
for i in t
7574
)
@@ -87,10 +86,7 @@ def get_references(t: str):
8786
if t:
8887
n = len(t) - 1
8988

90-
t = ", ".join(
91-
":obj:`{0} <pyrogram.api.functions.{0}>`".format(i)
92-
for i in t
93-
)
89+
t = ", ".join(":obj:`{0} <pyrogram.api.functions.{0}>`".format(i) for i in t)
9490

9591
if n:
9692
t = t.split(", ")
@@ -126,15 +122,9 @@ def get_argument_type(arg):
126122

127123

128124
class Combinator:
129-
def __init__(self,
130-
section: str,
131-
namespace: str,
132-
name: str,
133-
id: str,
134-
args: list,
135-
has_flags: bool,
136-
return_type: str,
137-
docs: str):
125+
def __init__(
126+
self, section: str, namespace: str, name: str, id: str, args: list, has_flags: bool, return_type: str, docs: str
127+
):
138128
self.section = section
139129
self.namespace = namespace
140130
self.name = name
@@ -170,9 +160,9 @@ def start():
170160
shutil.rmtree("{}/types".format(DESTINATION), ignore_errors=True)
171161
shutil.rmtree("{}/functions".format(DESTINATION), ignore_errors=True)
172162

173-
with open("{}/source/auth_key.tl".format(HOME), encoding="utf-8") as auth, \
174-
open("{}/source/sys_msgs.tl".format(HOME), encoding="utf-8") as system, \
175-
open("{}/source/main_api.tl".format(HOME), encoding="utf-8") as api:
163+
with open("{}/source/auth_key.tl".format(HOME), encoding="utf-8") as auth, open(
164+
"{}/source/sys_msgs.tl".format(HOME), encoding="utf-8"
165+
) as system, open("{}/source/main_api.tl".format(HOME), encoding="utf-8") as api:
176166
schema = (auth.read() + system.read() + api.read()).splitlines()
177167

178168
with open("{}/template/mtproto.txt".format(HOME), encoding="utf-8") as f:
@@ -236,11 +226,8 @@ def start():
236226
"0x{}".format(id.zfill(8)),
237227
args,
238228
has_flags,
239-
".".join(
240-
return_type.split(".")[:-1]
241-
+ [capit(return_type.split(".")[-1])]
242-
),
243-
docs
229+
".".join(return_type.split(".")[:-1] + [capit(return_type.split(".")[-1])]),
230+
docs,
244231
)
245232
)
246233

@@ -267,10 +254,13 @@ def start():
267254
total = len(combinators)
268255
current = 0
269256
for c in combinators: # type: Combinator
270-
print("Compiling APIs... [{}%] {}".format(
271-
str(round(current * 100 / total)).rjust(3),
272-
".".join(filter(None, [c.section, c.namespace, c.name]))
273-
), end=" \r", flush=True)
257+
print(
258+
"Compiling APIs... [{}%] {}".format(
259+
str(round(current * 100 / total)).rjust(3), ".".join(filter(None, [c.section, c.namespace, c.name]))
260+
),
261+
end=" \r",
262+
flush=True,
263+
)
274264
current += 1
275265

276266
path = "{}/{}/{}".format(DESTINATION, c.section, c.namespace)
@@ -287,13 +277,15 @@ def start():
287277

288278
sorted_args = sort_args(c.args)
289279

290-
arguments = ", " + ", ".join(
291-
[get_argument_type(i) for i in sorted_args if i != ("flags", "#")]
292-
) if c.args else ""
280+
arguments = (
281+
", " + ", ".join([get_argument_type(i) for i in sorted_args if i != ("flags", "#")]) if c.args else ""
282+
)
293283

294-
fields = "\n ".join(
295-
["self.{0} = {0} # {1}".format(i[0], i[1]) for i in c.args if i != ("flags", "#")]
296-
) if c.args else "pass"
284+
fields = (
285+
"\n ".join(["self.{0} = {0} # {1}".format(i[0], i[1]) for i in c.args if i != ("flags", "#")])
286+
if c.args
287+
else "pass"
288+
)
297289

298290
docstring_args = []
299291
docs = c.docs.split("|")[1:] if c.docs else None
@@ -313,15 +305,15 @@ def start():
313305
arg_name,
314306
get_docstring_arg_type(arg_type, is_pyrogram_type=True),
315307
", optional" if "Optional" in docs[i] else "",
316-
re.sub("Optional\. ", "", docs[i].split("§")[1].rstrip(".") + ".")
308+
re.sub("Optional\. ", "", docs[i].split("§")[1].rstrip(".") + "."),
317309
)
318310
)
319311
else:
320312
docstring_args.append(
321313
"{}{}: {}".format(
322314
arg_name,
323315
" (optional)".format(flag_number) if is_optional else "",
324-
get_docstring_arg_type(arg_type, is_pyrogram_type=c.namespace == "pyrogram")
316+
get_docstring_arg_type(arg_type, is_pyrogram_type=c.namespace == "pyrogram"),
325317
)
326318
)
327319

@@ -353,13 +345,12 @@ def start():
353345
flag = FLAGS_RE.match(i[1])
354346
if flag:
355347
write_flags.append(
356-
"flags |= (1 << {}) if self.{} is not None else 0".format(flag.group(1), i[0]))
348+
"flags |= (1 << {}) if self.{} is not None else 0".format(flag.group(1), i[0])
349+
)
357350

358-
write_flags = "\n ".join([
359-
"flags = 0",
360-
"\n ".join(write_flags),
361-
"b.write(Int(flags))\n "
362-
])
351+
write_flags = "\n ".join(
352+
["flags = 0", "\n ".join(write_flags), "b.write(Int(flags))\n "]
353+
)
363354

364355
write_types += write_flags
365356
read_types += "flags = Int.read(b)\n "
@@ -400,9 +391,7 @@ def start():
400391
write_types += "b.write(self.{}.write())\n ".format(arg_name)
401392

402393
read_types += "\n "
403-
read_types += "{} = Object.read(b) if flags & (1 << {}) else None\n ".format(
404-
arg_name, index
405-
)
394+
read_types += "{} = Object.read(b) if flags & (1 << {}) else None\n ".format(arg_name, index)
406395
else:
407396
if arg_type in core_types:
408397
write_types += "\n "
@@ -442,7 +431,7 @@ def start():
442431
docstring_args=docstring_args,
443432
object_id=c.id,
444433
arguments=arguments,
445-
fields=fields
434+
fields=fields,
446435
)
447436
)
448437
else:
@@ -456,7 +445,7 @@ def start():
456445
fields=fields,
457446
read_types=read_types,
458447
write_types=write_types,
459-
return_arguments=", ".join([i[0] for i in sorted_args if i != ("flags", "#")])
448+
return_arguments=", ".join([i[0] for i in sorted_args if i != ("flags", "#")]),
460449
)
461450
)
462451

@@ -467,17 +456,17 @@ def start():
467456

468457
for c in combinators:
469458
path = ".".join(filter(None, [c.section, c.namespace, capit(c.name)]))
470-
f.write("\n {}: \"pyrogram.api.{}\",".format(c.id, path))
471-
472-
f.write("\n 0xbc799737: \"pyrogram.api.core.BoolFalse\",")
473-
f.write("\n 0x997275b5: \"pyrogram.api.core.BoolTrue\",")
474-
f.write("\n 0x56730bcc: \"pyrogram.api.core.Null\",")
475-
f.write("\n 0x1cb5c415: \"pyrogram.api.core.Vector\",")
476-
f.write("\n 0x73f1f8dc: \"pyrogram.api.core.MsgContainer\",")
477-
f.write("\n 0xae500895: \"pyrogram.api.core.FutureSalts\",")
478-
f.write("\n 0x0949d9dc: \"pyrogram.api.core.FutureSalt\",")
479-
f.write("\n 0x3072cfa1: \"pyrogram.api.core.GzipPacked\",")
480-
f.write("\n 0x5bb8e511: \"pyrogram.api.core.Message\",")
459+
f.write('\n {}: "pyrogram.api.{}",'.format(c.id, path))
460+
461+
f.write('\n 0xbc799737: "pyrogram.api.core.BoolFalse",')
462+
f.write('\n 0x997275b5: "pyrogram.api.core.BoolTrue",')
463+
f.write('\n 0x56730bcc: "pyrogram.api.core.Null",')
464+
f.write('\n 0x1cb5c415: "pyrogram.api.core.Vector",')
465+
f.write('\n 0x73f1f8dc: "pyrogram.api.core.MsgContainer",')
466+
f.write('\n 0xae500895: "pyrogram.api.core.FutureSalts",')
467+
f.write('\n 0x0949d9dc: "pyrogram.api.core.FutureSalt",')
468+
f.write('\n 0x3072cfa1: "pyrogram.api.core.GzipPacked",')
469+
f.write('\n 0x5bb8e511: "pyrogram.api.core.Message",')
481470

482471
f.write("\n}\n")
483472

compiler/docs/compiler.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ def build(path, level=0):
6464
page_template.format(
6565
title=name,
6666
title_markup="=" * len(name),
67-
full_class_path="pyrogram.api.{}".format(
68-
os.path.splitext(full_path)[0].replace("/", ".")
69-
)
67+
full_class_path="pyrogram.api.{}".format(os.path.splitext(full_path)[0].replace("/", ".")),
7068
)
7169
)
7270

@@ -101,10 +99,7 @@ def build(path, level=0):
10199

102100
f.write(
103101
toctree.format(
104-
title=k.title(),
105-
title_markup="=" * len(k),
106-
module=module,
107-
entities="\n ".join(entities)
102+
title=k.title(), title_markup="=" * len(k), module=module, entities="\n ".join(entities)
108103
)
109104
)
110105

compiler/error/compiler.py

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

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

7980
super_class = caml(name)
@@ -94,7 +95,7 @@ def start():
9495

9596
sub_class = caml(re.sub(r"_X", "_", id))
9697

97-
f_all.write(" \"{}\": \"{}\",\n".format(id, sub_class))
98+
f_all.write(' "{}": "{}",\n'.format(id, sub_class))
9899

99100
sub_classes.append((sub_class, id, message))
100101

@@ -109,12 +110,17 @@ def start():
109110
super_class=super_class,
110111
code=code,
111112
docstring='"""{}"""'.format(name),
112-
sub_classes="".join([sub_class_template.format(
113-
sub_class=k[0],
114-
super_class=super_class,
115-
id="\"{}\"".format(k[1]),
116-
docstring='"""{}"""'.format(k[2])
117-
) for k in sub_classes])
113+
sub_classes="".join(
114+
[
115+
sub_class_template.format(
116+
sub_class=k[0],
117+
super_class=super_class,
118+
id='"{}"'.format(k[1]),
119+
docstring='"""{}"""'.format(k[2]),
120+
)
121+
for k in sub_classes
122+
]
123+
),
118124
)
119125

120126
f_class.write(class_template)

0 commit comments

Comments
 (0)