X Tutup
Skip to content

Commit 225bc24

Browse files
authored
Merge pull request python-telegram-bot#442 from python-telegram-bot/explicit-kwargs
Use explicit kwargs and change/add a bunch of documentation.
2 parents a5671a8 + a5f9aa3 commit 225bc24

40 files changed

+1060
-735
lines changed

telegram/audio.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,30 @@ class Audio(TelegramObject):
3535
Args:
3636
file_id (str):
3737
duration (int):
38-
**kwargs: Arbitrary keyword arguments.
39-
40-
Keyword Args:
4138
performer (Optional[str]):
4239
title (Optional[str]):
4340
mime_type (Optional[str]):
4441
file_size (Optional[int]):
42+
**kwargs: Arbitrary keyword arguments.
43+
4544
"""
4645

47-
def __init__(self, file_id, duration, **kwargs):
46+
def __init__(self,
47+
file_id,
48+
duration,
49+
performer='',
50+
title='',
51+
mime_type='',
52+
file_size=0,
53+
**kwargs):
4854
# Required
4955
self.file_id = str(file_id)
5056
self.duration = int(duration)
5157
# 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))
58+
self.performer = performer
59+
self.title = title
60+
self.mime_type = str(mime_type)
61+
self.file_size = int(file_size)
5662

5763
@staticmethod
5864
def de_json(data, bot):

telegram/bot.py

Lines changed: 501 additions & 564 deletions
Large diffs are not rendered by default.

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: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,36 @@ class Chat(TelegramObject):
3636
Args:
3737
id (int):
3838
type (str):
39-
**kwargs: Arbitrary keyword arguments.
40-
41-
Keyword Args:
42-
type (Optional[str]):
39+
title (Optional[str]):
40+
username(Optional[str]):
41+
first_name(Optional[str]):
42+
last_name(Optional[str]):
4343
bot (Optional[Bot]): The Bot to use for instance methods
44-
"""
44+
**kwargs (dict): Arbitrary keyword arguments.
4545
46+
"""
4647
PRIVATE = 'private'
4748
GROUP = 'group'
4849
SUPERGROUP = 'supergroup'
4950
CHANNEL = 'channel'
5051

51-
def __init__(self, id, type, bot=None, **kwargs):
52+
def __init__(self,
53+
id,
54+
type,
55+
title='',
56+
username='',
57+
first_name='',
58+
last_name='',
59+
bot=None,
60+
**kwargs):
5261
# Required
5362
self.id = int(id)
5463
self.type = type
5564
# 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', '')
65+
self.title = title
66+
self.username = username
67+
self.first_name = first_name
68+
self.last_name = last_name
6069

6170
self.bot = bot
6271

telegram/chatmember.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ class ChatMember(TelegramObject):
3232
Args:
3333
user (:class:`telegram.User`):
3434
status (str):
35-
"""
35+
**kwargs (dict): Arbitrary keyword arguments.
3636
37+
"""
3738
CREATOR = 'creator'
3839
ADMINISTRATOR = 'administrator'
3940
MEMBER = 'member'

telegram/choseninlineresult.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,16 @@ class ChosenInlineResult(TelegramObject):
3333
result_id (str):
3434
from_user (:class:`telegram.User`):
3535
query (str):
36+
location (:class:`telegram.Location`):
37+
inline_message_id (str):
3638
3739
Args:
3840
result_id (str):
3941
from_user (:class:`telegram.User`):
4042
query (str):
43+
location (Optional[:class:`telegram.Location`]):
44+
inline_message_id (Optional[str]):
45+
**kwargs (dict): Arbitrary keyword arguments.
4146
4247
"""
4348

telegram/contact.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,19 @@ class Contact(TelegramObject):
3333
Args:
3434
phone_number (str):
3535
first_name (str):
36-
**kwargs: Arbitrary keyword arguments.
37-
38-
Keyword Args:
3936
last_name (Optional[str]):
4037
user_id (Optional[int]):
38+
**kwargs: Arbitrary keyword arguments.
39+
4140
"""
4241

43-
def __init__(self, phone_number, first_name, **kwargs):
42+
def __init__(self, phone_number, first_name, last_name='', user_id=0, **kwargs):
4443
# Required
4544
self.phone_number = str(phone_number)
4645
self.first_name = first_name
4746
# Optionals
48-
self.last_name = kwargs.get('last_name', '')
49-
self.user_id = int(kwargs.get('user_id', 0))
47+
self.last_name = last_name
48+
self.user_id = int(user_id)
5049

5150
@staticmethod
5251
def de_json(data, bot):

telegram/document.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,22 @@ class Document(TelegramObject):
3333
3434
Args:
3535
file_id (str):
36-
**kwargs: Arbitrary keyword arguments.
37-
38-
Keyword Args:
3936
thumb (Optional[:class:`telegram.PhotoSize`]):
4037
file_name (Optional[str]):
4138
mime_type (Optional[str]):
4239
file_size (Optional[int]):
40+
**kwargs (dict): Arbitrary keyword arguments.
41+
4342
"""
4443

45-
def __init__(self, file_id, **kwargs):
44+
def __init__(self, file_id, thumb=None, file_name='', mime_type='', file_size=0, **kwargs):
4645
# Required
4746
self.file_id = str(file_id)
4847
# 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))
48+
self.thumb = thumb
49+
self.file_name = file_name
50+
self.mime_type = str(mime_type)
51+
self.file_size = int(file_size)
5352

5453
@staticmethod
5554
def de_json(data, bot):

telegram/file.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,19 @@ class File(TelegramObject):
3434
Args:
3535
file_id (str):
3636
bot (telegram.Bot):
37-
**kwargs: Arbitrary keyword arguments.
38-
39-
Keyword Args:
4037
file_size (Optional[int]):
4138
file_path (Optional[str]):
39+
**kwargs (dict): Arbitrary keyword arguments.
4240
4341
"""
4442

45-
def __init__(self, file_id, bot, **kwargs):
43+
def __init__(self, file_id, bot, file_size=0, file_path='', **kwargs):
4644
# Required
4745
self.file_id = str(file_id)
4846

4947
# Optionals
50-
self.file_size = int(kwargs.get('file_size', 0))
51-
self.file_path = str(kwargs.get('file_path', ''))
48+
self.file_size = int(file_size)
49+
self.file_path = str(file_path)
5250

5351
self.bot = bot
5452

telegram/forcereply.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,16 @@ class ForceReply(ReplyMarkup):
3030
3131
Args:
3232
force_reply (bool):
33-
**kwargs: Arbitrary keyword arguments.
34-
35-
Keyword Args:
3633
selective (Optional[bool]):
34+
**kwargs (dict): Arbitrary keyword arguments.
35+
3736
"""
3837

39-
def __init__(self, force_reply=True, **kwargs):
38+
def __init__(self, force_reply=True, selective=False, **kwargs):
4039
# Required
4140
self.force_reply = bool(force_reply)
4241
# Optionals
43-
self.selective = bool(kwargs.get('selective', False))
42+
self.selective = bool(selective)
4443

4544
@staticmethod
4645
def de_json(data, bot):

0 commit comments

Comments
 (0)
X Tutup