X Tutup
Skip to content

Commit e367b85

Browse files
committed
Use explicit kwargs for all class inits in pure api.
While not stickily necessary for most classes (since user isn't directly creating them) it still unifies our approach. However for some like ReplyKeyboardHide where users are making the classes themselves it should improve IDE autocomplete support.
1 parent b610316 commit e367b85

19 files changed

+167
-95
lines changed

telegram/audio.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,22 @@ class Audio(TelegramObject):
4444
file_size (Optional[int]):
4545
"""
4646

47-
def __init__(self, file_id, duration, **kwargs):
47+
def __init__(self,
48+
file_id,
49+
duration,
50+
performer='',
51+
title='',
52+
mime_type='',
53+
file_size=0,
54+
**kwargs):
4855
# Required
4956
self.file_id = str(file_id)
5057
self.duration = int(duration)
5158
# Optionals
52-
self.performer = kwargs.get('performer', '')
53-
self.title = kwargs.get('title', '')
54-
self.mime_type = str(kwargs.get('mime_type', ''))
55-
self.file_size = int(kwargs.get('file_size', 0))
59+
self.performer = performer
60+
self.title = title
61+
self.mime_type = str(mime_type)
62+
self.file_size = int(file_size)
5663

5764
@staticmethod
5865
def de_json(data, bot):

telegram/callbackquery.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@
2525
class CallbackQuery(TelegramObject):
2626
"""This object represents a Telegram CallbackQuery."""
2727

28-
def __init__(self, id, from_user, data, bot=None, **kwargs):
28+
def __init__(self, id, from_user, data, message=None, inline_message_id='', bot=None,
29+
**kwargs):
2930
# Required
3031
self.id = id
3132
self.from_user = from_user
3233
self.data = data
3334
# Optionals
34-
self.message = kwargs.get('message')
35-
self.inline_message_id = kwargs.get('inline_message_id', '')
35+
self.message = message
36+
self.inline_message_id = inline_message_id
3637

3738
self.bot = bot
3839

telegram/chat.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,23 @@ class Chat(TelegramObject):
4848
SUPERGROUP = 'supergroup'
4949
CHANNEL = 'channel'
5050

51-
def __init__(self, id, type, bot=None, **kwargs):
51+
def __init__(self,
52+
id,
53+
type,
54+
title='',
55+
username='',
56+
first_name='',
57+
last_name='',
58+
bot=None,
59+
**kwargs):
5260
# Required
5361
self.id = int(id)
5462
self.type = type
5563
# Optionals
56-
self.title = kwargs.get('title', '')
57-
self.username = kwargs.get('username', '')
58-
self.first_name = kwargs.get('first_name', '')
59-
self.last_name = kwargs.get('last_name', '')
64+
self.title = title
65+
self.username = username
66+
self.first_name = first_name
67+
self.last_name = last_name
6068

6169
self.bot = bot
6270

telegram/contact.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ class Contact(TelegramObject):
4040
user_id (Optional[int]):
4141
"""
4242

43-
def __init__(self, phone_number, first_name, **kwargs):
43+
def __init__(self, phone_number, first_name, last_name='', user_id=0, **kwargs):
4444
# Required
4545
self.phone_number = str(phone_number)
4646
self.first_name = first_name
4747
# Optionals
48-
self.last_name = kwargs.get('last_name', '')
49-
self.user_id = int(kwargs.get('user_id', 0))
48+
self.last_name = last_name
49+
self.user_id = int(user_id)
5050

5151
@staticmethod
5252
def de_json(data, bot):

telegram/document.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ class Document(TelegramObject):
4242
file_size (Optional[int]):
4343
"""
4444

45-
def __init__(self, file_id, **kwargs):
45+
def __init__(self, file_id, thumb=None, file_name='', mime_type='', file_size=0, **kwargs):
4646
# Required
4747
self.file_id = str(file_id)
4848
# Optionals
49-
self.thumb = kwargs.get('thumb')
50-
self.file_name = kwargs.get('file_name', '')
51-
self.mime_type = str(kwargs.get('mime_type', ''))
52-
self.file_size = int(kwargs.get('file_size', 0))
49+
self.thumb = thumb
50+
self.file_name = file_name
51+
self.mime_type = str(mime_type)
52+
self.file_size = int(file_size)
5353

5454
@staticmethod
5555
def de_json(data, bot):

telegram/file.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ class File(TelegramObject):
4242
4343
"""
4444

45-
def __init__(self, file_id, bot, **kwargs):
45+
def __init__(self, file_id, bot, file_size=0, file_path='', **kwargs):
4646
# Required
4747
self.file_id = str(file_id)
4848

4949
# Optionals
50-
self.file_size = int(kwargs.get('file_size', 0))
51-
self.file_path = str(kwargs.get('file_path', ''))
50+
self.file_size = int(file_size)
51+
self.file_path = str(file_path)
5252

5353
self.bot = bot
5454

telegram/forcereply.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ class ForceReply(ReplyMarkup):
3636
selective (Optional[bool]):
3737
"""
3838

39-
def __init__(self, force_reply=True, **kwargs):
39+
def __init__(self, force_reply=True, selective=False, **kwargs):
4040
# Required
4141
self.force_reply = bool(force_reply)
4242
# Optionals
43-
self.selective = bool(kwargs.get('selective', False))
43+
self.selective = bool(selective)
4444

4545
@staticmethod
4646
def de_json(data, bot):

telegram/inlinekeyboardbutton.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ class InlineKeyboardButton(TelegramObject):
4242
4343
"""
4444

45-
def __init__(self, text, **kwargs):
45+
def __init__(self, text, url=None, callback_data=None, switch_inline_query=None, **kwargs):
4646
# Required
4747
self.text = text
4848

4949
# Optionals
50-
self.url = kwargs.get('url')
51-
self.callback_data = kwargs.get('callback_data')
52-
self.switch_inline_query = kwargs.get('switch_inline_query')
50+
self.url = url
51+
self.callback_data = callback_data
52+
self.switch_inline_query = switch_inline_query
5353

5454
@staticmethod
5555
def de_json(data, bot):

telegram/inlinequery.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ class InlineQuery(TelegramObject):
4545
bot (Optional[Bot]): The Bot to use for instance methods
4646
"""
4747

48-
def __init__(self, id, from_user, query, offset, bot=None, **kwargs):
48+
def __init__(self, id, from_user, query, offset, location=None, bot=None, **kwargs):
4949
# Required
5050
self.id = id
5151
self.from_user = from_user
5252
self.query = query
5353
self.offset = offset
5454

5555
# Optional
56-
self.location = kwargs.get('location')
56+
self.location = location
5757

5858
self.bot = bot
5959

telegram/message.py

Lines changed: 65 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -106,41 +106,77 @@ class Message(TelegramObject):
106106
bot (Optional[Bot]): The Bot to use for instance methods
107107
"""
108108

109-
def __init__(self, message_id, from_user, date, chat, bot=None, **kwargs):
109+
def __init__(self,
110+
message_id,
111+
from_user,
112+
date,
113+
chat,
114+
forward_from=None,
115+
forward_from_chat=None,
116+
forward_date=None,
117+
reply_to_message=None,
118+
edit_date=None,
119+
text='',
120+
entities=None,
121+
audio=None,
122+
document=None,
123+
photo=None,
124+
sticker=None,
125+
video=None,
126+
voice=None,
127+
caption='',
128+
contact=None,
129+
location=None,
130+
venue=None,
131+
new_chat_member=None,
132+
left_chat_member=None,
133+
new_chat_title='',
134+
new_chat_photo=None,
135+
delete_chat_photo=False,
136+
group_chat_created=False,
137+
supergroup_chat_created=False,
138+
migrate_to_chat_id=0,
139+
migrate_from_chat_id=0,
140+
channel_chat_created=False,
141+
pinned_message=None,
142+
bot=None,
143+
**kwargs):
110144
# Required
111145
self.message_id = int(message_id)
112146
self.from_user = from_user
113147
self.date = date
114148
self.chat = chat
115149
# Optionals
116-
self.forward_from = kwargs.get('forward_from')
117-
self.forward_from_chat = kwargs.get('forward_from_chat')
118-
self.forward_date = kwargs.get('forward_date')
119-
self.reply_to_message = kwargs.get('reply_to_message')
120-
self.edit_date = kwargs.get('edit_date')
121-
self.text = kwargs.get('text', '')
122-
self.entities = kwargs.get('entities', list())
123-
self.audio = kwargs.get('audio')
124-
self.document = kwargs.get('document')
125-
self.photo = kwargs.get('photo')
126-
self.sticker = kwargs.get('sticker')
127-
self.video = kwargs.get('video')
128-
self.voice = kwargs.get('voice')
129-
self.caption = kwargs.get('caption', '')
130-
self.contact = kwargs.get('contact')
131-
self.location = kwargs.get('location')
132-
self.venue = kwargs.get('venue')
133-
self.new_chat_member = kwargs.get('new_chat_member')
134-
self.left_chat_member = kwargs.get('left_chat_member')
135-
self.new_chat_title = kwargs.get('new_chat_title', '')
136-
self.new_chat_photo = kwargs.get('new_chat_photo')
137-
self.delete_chat_photo = bool(kwargs.get('delete_chat_photo', False))
138-
self.group_chat_created = bool(kwargs.get('group_chat_created', False))
139-
self.supergroup_chat_created = bool(kwargs.get('supergroup_chat_created', False))
140-
self.migrate_to_chat_id = int(kwargs.get('migrate_to_chat_id', 0))
141-
self.migrate_from_chat_id = int(kwargs.get('migrate_from_chat_id', 0))
142-
self.channel_chat_created = bool(kwargs.get('channel_chat_created', False))
143-
self.pinned_message = kwargs.get('pinned_message')
150+
self.forward_from = forward_from
151+
self.forward_from_chat = forward_from_chat
152+
self.forward_date = forward_date
153+
self.reply_to_message = reply_to_message
154+
self.edit_date = edit_date
155+
self.text = text
156+
if entities is None:
157+
entities = list()
158+
self.entities = entities
159+
self.audio = audio
160+
self.document = document
161+
self.photo = photo
162+
self.sticker = sticker
163+
self.video = video
164+
self.voice = voice
165+
self.caption = caption
166+
self.contact = contact
167+
self.location = location
168+
self.venue = venue
169+
self.new_chat_member = new_chat_member
170+
self.left_chat_member = left_chat_member
171+
self.new_chat_title = new_chat_title
172+
self.new_chat_photo = new_chat_photo
173+
self.delete_chat_photo = bool(delete_chat_photo)
174+
self.group_chat_created = bool(group_chat_created)
175+
self.supergroup_chat_created = bool(supergroup_chat_created)
176+
self.migrate_to_chat_id = int(migrate_to_chat_id)
177+
self.migrate_from_chat_id = int(migrate_from_chat_id)
178+
self.channel_chat_created = bool(channel_chat_created)
179+
self.pinned_message = pinned_message
144180

145181
self.bot = bot
146182

0 commit comments

Comments
 (0)
X Tutup