Skip to content

Commit 9b5e014

Browse files
saschalalalajh0ker
authored andcommitted
Simplification of boolean checks (python-telegram-bot#662)
* Simplification of boolean checks * Cast ok to bool for Telegram API json encoding
1 parent 845312d commit 9b5e014

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

telegram/bot.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,12 +1960,14 @@ def answer_shipping_query(self,
19601960
19611961
"""
19621962

1963-
if ok is True and (shipping_options is None or error_message is not None):
1963+
ok = bool(ok)
1964+
1965+
if ok and (shipping_options is None or error_message is not None):
19641966
raise TelegramError(
19651967
'answerShippingQuery: If ok is True, shipping_options '
19661968
'should not be empty and there should not be error_message')
19671969

1968-
if ok is False and (shipping_options is not None or error_message is None):
1970+
if not ok and (shipping_options is not None or error_message is None):
19691971
raise TelegramError(
19701972
'answerShippingQuery: If ok is False, error_message '
19711973
'should not be empty and there should not be shipping_options')
@@ -1974,7 +1976,7 @@ def answer_shipping_query(self,
19741976

19751977
data = {'shipping_query_id': shipping_query_id, 'ok': ok}
19761978

1977-
if ok is True:
1979+
if ok:
19781980
data['shipping_options'] = [option.to_dict() for option in shipping_options]
19791981
if error_message is not None:
19801982
data['error_message'] = error_message
@@ -2009,6 +2011,8 @@ def answer_pre_checkout_query(self, pre_checkout_query_id, ok,
20092011
20102012
"""
20112013

2014+
ok = bool(ok)
2015+
20122016
if not (ok ^ (error_message is not None)):
20132017
raise TelegramError(
20142018
'answerPreCheckoutQuery: If ok is True, there should '

0 commit comments

Comments
 (0)