Force named arguments on Pyrogram types · stack-queue/pyrogram@c6a0bf0 · GitHub
Skip to content

Commit c6a0bf0

Browse files
committed
Force named arguments on Pyrogram types
1 parent 7430529 commit c6a0bf0

25 files changed

Lines changed: 119 additions & 156 deletions

pyrogram/client/types/messages_and_media/animation.py

Lines changed: 4 additions & 6 deletions

pyrogram/client/types/messages_and_media/audio.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,11 @@ class Audio(PyrogramType):
5656
Title of the audio as defined by sender or by audio tags.
5757
"""
5858

59-
def __init__(self, file_id: str, duration: int, *,
60-
thumb=None, file_name: str = None, mime_type: str = None, file_size: int = None, date: int = None,
61-
performer: str = None, title: str = None,
62-
client=None, raw=None):
59+
def __init__(self, *, client, raw, file_id: str, duration: int, thumb=None, file_name: str = None,
60+
mime_type: str = None, file_size: int = None, date: int = None, performer: str = None,
61+
title: str = None):
62+
super().__init__(client, raw)
63+
6364
self.file_id = file_id
6465
self.thumb = thumb
6566
self.file_name = file_name
@@ -70,9 +71,6 @@ def __init__(self, file_id: str, duration: int, *,
7071
self.performer = performer
7172
self.title = title
7273

73-
self._client = client
74-
self._raw = raw
75-
7674
@staticmethod
7775
def parse(client, audio: types.Document, audio_attributes: types.DocumentAttributeAudio, file_name: str) -> "Audio":
7876
return Audio(

pyrogram/client/types/messages_and_media/contact.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,16 @@ class Contact(PyrogramType):
4040
Additional data about the contact in the form of a vCard.
4141
"""
4242

43-
def __init__(self, phone_number: str, first_name: str, *,
44-
last_name: str = None, user_id: int = None, vcard: str = None,
45-
client=None, raw=None):
43+
def __init__(self, *, client, raw, phone_number: str, first_name: str, last_name: str = None, user_id: int = None,
44+
vcard: str = None):
45+
super().__init__(client, raw)
46+
4647
self.phone_number = phone_number
4748
self.first_name = first_name
4849
self.last_name = last_name
4950
self.user_id = user_id
5051
self.vcard = vcard
5152

52-
self._client = client
53-
self._raw = raw
54-
5553
@staticmethod
5654
def parse(client, contact: types.MessageMediaContact) -> "Contact":
5755
return Contact(

pyrogram/client/types/messages_and_media/document.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,17 @@ class Document(PyrogramType):
4747
Date the document was sent in Unix time.
4848
"""
4949

50-
def __init__(self, file_id: str, *,
51-
thumb=None, file_name: str = None, mime_type: str = None, file_size: int = None, date: int = None,
52-
client=None, raw=None):
50+
def __init__(self, *, client, raw, file_id: str, thumb=None, file_name: str = None, mime_type: str = None,
51+
file_size: int = None, date: int = None):
52+
super().__init__(client, raw)
53+
5354
self.file_id = file_id
5455
self.thumb = thumb
5556
self.file_name = file_name
5657
self.mime_type = mime_type
5758
self.file_size = file_size
5859
self.date = date
5960

60-
self._client = client
61-
self._raw = raw
62-
6361
@staticmethod
6462
def parse(client, document: types.Document, file_name: str) -> "Document":
6563
return Document(

pyrogram/client/types/messages_and_media/location.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@ class Location(PyrogramType):
3131
Latitude as defined by sender.
3232
"""
3333

34-
def __init__(self, longitude: float, latitude: float, *,
35-
client=None, raw=None):
34+
def __init__(self, *, client, raw, longitude: float, latitude: float, ):
35+
super().__init__(client, raw)
36+
3637
self.longitude = longitude
3738
self.latitude = latitude
3839

39-
self._client = client
40-
self._raw = raw
41-
4240
@staticmethod
4341
def parse(client, geo_point: types.GeoPoint) -> "Location":
4442
if isinstance(geo_point, types.GeoPoint):

pyrogram/client/types/messages_and_media/message.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -225,20 +225,20 @@ class Message(PyrogramType):
225225

226226
# TODO: Add game missing field. Also invoice, successful_payment, connected_website
227227

228-
def __init__(self, message_id: int, *,
229-
date: int = None, chat=None, from_user=None, forward_from=None, forward_from_chat=None,
230-
forward_from_message_id: int = None, forward_signature: str = None, forward_date: int = None,
231-
reply_to_message=None, mentioned=None, empty=None, service=None, media=None, edit_date: int = None,
232-
media_group_id: str = None, author_signature: str = None, text: str = None, entities: list = None,
233-
caption_entities: list = None, audio=None, document=None, photo=None, sticker=None, animation=None,
234-
video=None, voice=None, video_note=None, caption: str = None, contact=None, location=None, venue=None,
235-
web_page=None, new_chat_members: list = None, left_chat_member=None, new_chat_title: str = None,
236-
new_chat_photo=None, delete_chat_photo: bool = None, group_chat_created: bool = None,
237-
supergroup_chat_created: bool = None, channel_chat_created: bool = None,
238-
migrate_to_chat_id: int = None, migrate_from_chat_id: int = None, pinned_message=None,
239-
views: int = None, via_bot=None, outgoing: bool = None, matches: list = None, command: list = None,
240-
reply_markup=None,
241-
client=None, raw=None):
228+
def __init__(self, *, client, raw, message_id: int, date: int = None, chat=None, from_user=None, forward_from=None,
229+
forward_from_chat=None, forward_from_message_id: int = None, forward_signature: str = None,
230+
forward_date: int = None, reply_to_message=None, mentioned=None, empty=None, service=None, media=None,
231+
edit_date: int = None, media_group_id: str = None, author_signature: str = None, text: str = None,
232+
entities: list = None, caption_entities: list = None, audio=None, document=None, photo=None,
233+
sticker=None, animation=None, video=None, voice=None, video_note=None, caption: str = None,
234+
contact=None, location=None, venue=None, web_page=None, new_chat_members: list = None,
235+
left_chat_member=None, new_chat_title: str = None, new_chat_photo=None, delete_chat_photo: bool = None,
236+
group_chat_created: bool = None, supergroup_chat_created: bool = None,
237+
channel_chat_created: bool = None, migrate_to_chat_id: int = None, migrate_from_chat_id: int = None,
238+
pinned_message=None, views: int = None, via_bot=None, outgoing: bool = None, matches: list = None,
239+
command: list = None, reply_markup=None):
240+
super().__init__(client, raw)
241+
242242
self.message_id = message_id
243243
self.date = date
244244
self.chat = chat
@@ -290,9 +290,6 @@ def __init__(self, message_id: int, *,
290290
self.command = command
291291
self.reply_markup = reply_markup
292292

293-
self._client = client
294-
self._raw = raw
295-
296293
@staticmethod
297294
def parse(client, message: types.Message or types.MessageService or types.MessageEmpty, users: dict, chats: dict,
298295
replies: int = 1):

pyrogram/client/types/messages_and_media/message_entity.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,15 @@ class MessageEntity(PyrogramType):
6161
types.MessageEntityPhone.ID: "phone_number"
6262
}
6363

64-
def __init__(self, type: str, offset: int, length: int, *,
65-
url: str = None, user=None,
66-
client=None, raw=None):
64+
def __init__(self, *, client, raw, type: str, offset: int, length: int, url: str = None, user=None):
65+
super().__init__(client, raw)
66+
6767
self.type = type
6868
self.offset = offset
6969
self.length = length
7070
self.url = url
7171
self.user = user
7272

73-
self._client = client
74-
self._raw = raw
75-
7673
@staticmethod
7774
def parse(client, entity, users: dict) -> "MessageEntity" or None:
7875
type = MessageEntity.ENTITIES.get(entity.ID, None)
@@ -85,5 +82,7 @@ def parse(client, entity, users: dict) -> "MessageEntity" or None:
8582
offset=entity.offset,
8683
length=entity.length,
8784
url=getattr(entity, "url", None),
88-
user=User.parse(client, users.get(getattr(entity, "user_id", None), None))
85+
user=User.parse(client, users.get(getattr(entity, "user_id", None), None)),
86+
client=client,
87+
raw=entity
8988
)

pyrogram/client/types/messages_and_media/messages.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class Messages(PyrogramType):
3030
Requested messages.
3131
"""
3232

33-
def __init__(self, total_count: int, messages: list):
33+
def __init__(self, *, client, raw, total_count: int, messages: list):
34+
super().__init__(client, raw)
35+
3436
self.total_count = total_count
3537
self.messages = messages

pyrogram/client/types/messages_and_media/photo.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,13 @@ class Photo(PyrogramType):
3939
Available sizes of this photo.
4040
"""
4141

42-
def __init__(self, id: str, date: int, sizes: list, *,
43-
client=None, raw=None):
42+
def __init__(self, *, client, raw, id: str, date: int, sizes: list):
43+
super().__init__(client, raw)
44+
4445
self.id = id
4546
self.date = date
4647
self.sizes = sizes
4748

48-
self._client = client
49-
self._raw = raw
50-
5149
@staticmethod
5250
def parse(client, photo: types.Photo):
5351
if isinstance(photo, types.Photo):

pyrogram/client/types/messages_and_media/photo_size.py

Lines changed: 3 additions & 5 deletions

0 commit comments

Comments
 (0)