if
statements can be merged PTC-W0048 47async def summoned(bot: UserBot, message: Message):
48 chat_details = SUMMON().find_chat_id(message)
49
50 if chat_details is not None: 51 if chat_details["chat_id"] == message.chat.id:
52 if not AFK:
53 try:
47 try:
48 chat_details = StickerDeleter().find_chat_id(message)
49
50 if chat_details is not None:51 if chat_details["chat_id"] == message.chat.id \
52 and chat_details['sticker_id'] == message.sticker.file_unique_id:
53 await message.delete()
91 )
92
93 def calculate_retard_level(self, user_id):
94 if self.check_if_warned(user_id): 95 if self.check_if_approved(user_id) is False:
96 to_calculate = self.pm_table.find_one({"user_id": user_id})
97
77 return True
78
79 def increment_retard_level(self, user_id):
80 if self.check_if_warned(user_id): 81 if self.check_if_approved(user_id) is False:
82 to_increment = self.pm_table.find_one({"user_id": user_id})
83
Nested if
statements can be collapsed into a single if
statement by separating their condition using and
operator.
Merging collapsible if
statements increases the code's readability.
if condition1:
if condition2:
dosomething()
if condition1 and condition2:
dosomething()
DeepSource will not raise this issue when the nested if
statements have comments in between them, as it could be explaining why the nested if
is in place.