elif
/ else
block after continue
PYL-R1724 39 is_genius = gatekeeper.has(ctx.guild, ctx.author, 4)
40 submod = ctx.guild.get_role(guild_service.get_guild().role_sub_mod)
41
42 if not cog.__cog_app_commands__: 43 continue
44 elif cog_name in self.mod_only and not is_mod:
45 continue
The use of else
or elif
becomes redundant and can be dropped if the last statement under the leading if
/ elif
block is a continue
statement.
In the case of an elif
after continue
, it can be written as a separate if
block.
For else
blocks after continue
, the statements can be shifted out of else
. Please refer to the examples below for reference.
Refactoring the code this way can improve code-readability and make it easier to maintain.
def classify_number(x):
for num in range(x):
if x % 2 == 0:
continue
else:
print(f"{num} is Odd}")
def classify_number(x):
for num in range(x):
if x % 2 == 0:
continue
print(f"{num} is Odd}")