Simplification of boolean checks (#662)

* Simplification of boolean checks

* Cast ok to bool for Telegram API json encoding
This commit is contained in:
saschalalala 2017-06-18 12:09:32 +02:00 committed by Jannes Höke
parent 845312da59
commit 9b5e014a0a

View file

@ -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 '