if
statements can be merged PTC-W0048104 parts = [formatted[i:i+1900] for i in range(0, len(formatted), 1900)]
105 for i, part in enumerate(parts):
106 content = f"{self.prefixcalc(record.levelname)}{part}{self.suffixcalc(record.levelname)}"
107 if i == len(parts) - 1:108 if record.levelname == 'ERROR' or record.levelname == 'CRITICAL':
109 content += f'<@{os.environ.get("OWNER_ID")}>'
110 message_body = {
127 pattern = re.compile(
128 r"(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*))")
129 link = pattern.search(msg.content)
130 if (link):131 if link.group(0):
132 link = link.group(0)
133
190 await ctx.defer()
191 for channel in channels:
192 channel = ctx.guild.get_channel(channel)
193 if channel is not None:194 if await self.lock_unlock_channel(ctx, channel, lock=True):
195 locked.append(channel)
196
213 await ctx.defer()
214 for channel in channels:
215 channel = ctx.guild.get_channel(channel)
216 if channel is not None:217 if await self.lock_unlock_channel(ctx, channel, lock=None):
218 unlocked.append(channel)
219
1856 # If the user invoking this command is not in the same channel, return error
1857 if not ctx.author.voice or not ctx.author.voice.channel or (ctx.voice_state.voice and ctx.author.voice.channel != ctx.voice_state.voice.channel):
1858 return await self.respond(ctx.ctx, loc["messages"]["enter_before_play"], color=0xff0000)
1859 if ctx.voice_client:1860 if ctx.voice_client.channel != ctx.author.voice.channel:
1861 return await self.respond(ctx.ctx, loc["messages"]["already_in_voice"], color=0xff0000)
1862 if len(args) < 3 or args[2] == "":
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.