Skip to content

Commit 34b51b6

Browse files
committed
Force keyword arguments for all TL types
1 parent e0f1f6a commit 34b51b6

28 files changed

+133
-108
lines changed

compiler/api/compiler.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,11 @@ def start():
287287

288288
sorted_args = sort_args(c.args)
289289

290-
arguments = ", " + ", ".join(
291-
[get_argument_type(i) for i in sorted_args if i != ("flags", "#")]
292-
) if c.args else ""
290+
arguments = (
291+
", "
292+
+ ("*, " if c.args else "")
293+
+ (", ".join([get_argument_type(i) for i in sorted_args if i != ("flags", "#")]) if c.args else "")
294+
)
293295

294296
fields = "\n ".join(
295297
["self.{0} = {0} # {1}".format(i[0], i[1]) for i in c.args if i != ("flags", "#")]
@@ -456,7 +458,9 @@ def start():
456458
fields=fields,
457459
read_types=read_types,
458460
write_types=write_types,
459-
return_arguments=", ".join([i[0] for i in sorted_args if i != ("flags", "#")]),
461+
return_arguments=", ".join(
462+
["{0}={0}".format(i[0]) for i in sorted_args if i != ("flags", "#")]
463+
),
460464
slots=", ".join(['"{}"'.format(i[0]) for i in sorted_args if i != ("flags", "#")]),
461465
qualname="{}{}".format("{}.".format(c.namespace) if c.namespace else "", c.name)
462466
)

pyrogram/client/client.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -627,9 +627,9 @@ def default_phone_number_callback():
627627
try:
628628
r = self.send(
629629
functions.auth.SignIn(
630-
self.phone_number,
631-
phone_code_hash,
632-
self.phone_code
630+
phone_number=self.phone_number,
631+
phone_code_hash=phone_code_hash,
632+
phone_code=self.phone_code
633633
)
634634
)
635635
except PhoneNumberUnoccupied:
@@ -640,11 +640,11 @@ def default_phone_number_callback():
640640
try:
641641
r = self.send(
642642
functions.auth.SignUp(
643-
self.phone_number,
644-
phone_code_hash,
645-
self.phone_code,
646-
self.first_name,
647-
self.last_name
643+
phone_number=self.phone_number,
644+
phone_code_hash=phone_code_hash,
645+
phone_code=self.phone_code,
646+
first_name=self.first_name,
647+
last_name=self.last_name
648648
)
649649
)
650650
except PhoneNumberOccupied:
@@ -738,7 +738,11 @@ def default_recovery_callback(email_pattern: str) -> str:
738738
break
739739

740740
if terms_of_service:
741-
assert self.send(functions.help.AcceptTermsOfService(terms_of_service.id))
741+
assert self.send(
742+
functions.help.AcceptTermsOfService(
743+
id=terms_of_service.id
744+
)
745+
)
742746

743747
self.password = None
744748
self.user_id = r.user.id
@@ -1036,10 +1040,10 @@ def send(self,
10361040
raise ConnectionError("Client has not been started")
10371041

10381042
if self.no_updates:
1039-
data = functions.InvokeWithoutUpdates(data)
1043+
data = functions.InvokeWithoutUpdates(query=data)
10401044

10411045
if self.takeout_id:
1042-
data = functions.InvokeWithTakeout(self.takeout_id, data)
1046+
data = functions.InvokeWithTakeout(takeout_id=self.takeout_id, query=data)
10431047

10441048
r = self.session.send(data, retries, timeout)
10451049

@@ -1353,15 +1357,15 @@ def resolve_peer(self,
13531357
self.fetch_peers(
13541358
self.send(
13551359
functions.users.GetUsers(
1356-
id=[types.InputUser(peer_id, 0)]
1360+
id=[types.InputUser(user_id=peer_id, access_hash=0)]
13571361
)
13581362
)
13591363
)
13601364
else:
13611365
if str(peer_id).startswith("-100"):
13621366
self.send(
13631367
functions.channels.GetChannels(
1364-
id=[types.InputChannel(int(str(peer_id)[4:]), 0)]
1368+
id=[types.InputChannel(channel_id=int(str(peer_id)[4:]), access_hash=0)]
13651369
)
13661370
)
13671371
else:
@@ -1668,8 +1672,8 @@ def get_file(self,
16681672

16691673
hashes = session.send(
16701674
functions.upload.GetCdnFileHashes(
1671-
r.file_token,
1672-
offset
1675+
file_token=r.file_token,
1676+
offset=offset
16731677
)
16741678
)
16751679

pyrogram/client/ext/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ def get_peer_id(input_peer) -> int:
6767

6868
def get_input_peer(peer_id: int, access_hash: int):
6969
return (
70-
types.InputPeerUser(peer_id, access_hash) if peer_id > 0
71-
else types.InputPeerChannel(int(str(peer_id)[4:]), access_hash)
70+
types.InputPeerUser(user_id=peer_id, access_hash=access_hash) if peer_id > 0
71+
else types.InputPeerChannel(channel_id=int(str(peer_id)[4:]), access_hash=access_hash)
7272
if (str(peer_id).startswith("-100") and access_hash)
73-
else types.InputPeerChat(-peer_id)
73+
else types.InputPeerChat(chat_id=-peer_id)
7474
)
7575

7676

pyrogram/client/methods/chats/export_chat_invite_link.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def export_chat_invite_link(self,
4545
if isinstance(peer, types.InputPeerChat):
4646
return self.send(
4747
functions.messages.ExportChatInvite(
48-
chat_id=peer.chat_id
48+
peer=peer.chat_id
4949
)
5050
).link
5151
elif isinstance(peer, types.InputPeerChannel):

pyrogram/client/methods/chats/get_chat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ def get_chat(self,
6767
peer = self.resolve_peer(chat_id)
6868

6969
if isinstance(peer, types.InputPeerChannel):
70-
r = self.send(functions.channels.GetFullChannel(peer))
70+
r = self.send(functions.channels.GetFullChannel(channel=peer))
7171
elif isinstance(peer, (types.InputPeerUser, types.InputPeerSelf)):
72-
r = self.send(functions.users.GetFullUser(peer))
72+
r = self.send(functions.users.GetFullUser(id=peer))
7373
else:
74-
r = self.send(functions.messages.GetFullChat(peer.chat_id))
74+
r = self.send(functions.messages.GetFullChat(chat_id=peer.chat_id))
7575

7676
return pyrogram.Chat._parse_full(self, r)

pyrogram/client/methods/chats/get_chat_members.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def get_chat_members(self,
9292
self,
9393
self.send(
9494
functions.messages.GetFullChat(
95-
peer.chat_id
95+
chat_id=peer.chat_id
9696
)
9797
)
9898
)

pyrogram/client/methods/contacts/get_contacts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def get_contacts(self):
3939
"""
4040
while True:
4141
try:
42-
contacts = self.send(functions.contacts.GetContacts(0))
42+
contacts = self.send(functions.contacts.GetContacts(hash=0))
4343
except FloodWait as e:
4444
log.warning("get_contacts flood: waiting {} seconds".format(e.x))
4545
time.sleep(e.x)

pyrogram/client/methods/messages/edit_message_media.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ def edit_message_media(self,
131131
w=media.width,
132132
h=media.height
133133
),
134-
types.DocumentAttributeFilename(os.path.basename(media.media))
134+
types.DocumentAttributeFilename(
135+
file_name=os.path.basename(media.media)
136+
)
135137
]
136138
)
137139
)
@@ -187,7 +189,9 @@ def edit_message_media(self,
187189
performer=media.performer,
188190
title=media.title
189191
),
190-
types.DocumentAttributeFilename(os.path.basename(media.media))
192+
types.DocumentAttributeFilename(
193+
file_name=os.path.basename(media.media)
194+
)
191195
]
192196
)
193197
)
@@ -244,7 +248,9 @@ def edit_message_media(self,
244248
w=media.width,
245249
h=media.height
246250
),
247-
types.DocumentAttributeFilename(os.path.basename(media.media)),
251+
types.DocumentAttributeFilename(
252+
file_name=os.path.basename(media.media)
253+
),
248254
types.DocumentAttributeAnimated()
249255
]
250256
)
@@ -296,7 +302,9 @@ def edit_message_media(self,
296302
thumb=None if media.thumb is None else self.save_file(media.thumb),
297303
file=self.save_file(media.media),
298304
attributes=[
299-
types.DocumentAttributeFilename(os.path.basename(media.media))
305+
types.DocumentAttributeFilename(
306+
file_name=os.path.basename(media.media)
307+
)
300308
]
301309
)
302310
)

pyrogram/client/methods/messages/get_messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def get_messages(self,
7676

7777
is_iterable = not isinstance(ids, int)
7878
ids = list(ids) if is_iterable else [ids]
79-
ids = [ids_type(i) for i in ids]
79+
ids = [ids_type(id=i) for i in ids]
8080

8181
if isinstance(peer, types.InputPeerChannel):
8282
rpc = functions.channels.GetMessages(channel=peer, id=ids)

pyrogram/client/methods/messages/send_animation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def send_animation(self,
141141
w=width,
142142
h=height
143143
),
144-
types.DocumentAttributeFilename(os.path.basename(animation)),
144+
types.DocumentAttributeFilename(file_name=os.path.basename(animation)),
145145
types.DocumentAttributeAnimated()
146146
]
147147
)

0 commit comments

Comments
 (0)