mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-22 22:45:09 +01:00
Simplification of boolean checks (#662)
* Simplification of boolean checks * Cast ok to bool for Telegram API json encoding
This commit is contained in:
parent
845312da59
commit
9b5e014a0a
1 changed files with 7 additions and 3 deletions
|
@ -1960,12 +1960,14 @@ class Bot(TelegramObject):
|
|||
|
||||
"""
|
||||
|
||||
if ok is True and (shipping_options is None or error_message is not None):
|
||||
ok = bool(ok)
|
||||
|
||||
if ok and (shipping_options is None or error_message is not None):
|
||||
raise TelegramError(
|
||||
'answerShippingQuery: If ok is True, shipping_options '
|
||||
'should not be empty and there should not be error_message')
|
||||
|
||||
if ok is False and (shipping_options is not None or error_message is None):
|
||||
if not ok and (shipping_options is not None or error_message is None):
|
||||
raise TelegramError(
|
||||
'answerShippingQuery: If ok is False, error_message '
|
||||
'should not be empty and there should not be shipping_options')
|
||||
|
@ -1974,7 +1976,7 @@ class Bot(TelegramObject):
|
|||
|
||||
data = {'shipping_query_id': shipping_query_id, 'ok': ok}
|
||||
|
||||
if ok is True:
|
||||
if ok:
|
||||
data['shipping_options'] = [option.to_dict() for option in shipping_options]
|
||||
if error_message is not None:
|
||||
data['error_message'] = error_message
|
||||
|
@ -2009,6 +2011,8 @@ class Bot(TelegramObject):
|
|||
|
||||
"""
|
||||
|
||||
ok = bool(ok)
|
||||
|
||||
if not (ok ^ (error_message is not None)):
|
||||
raise TelegramError(
|
||||
'answerPreCheckoutQuery: If ok is True, there should '
|
||||
|
|
Loading…
Reference in a new issue