mirror of
https://github.com/Fluffy-Bean/Lynxie.git
synced 2025-05-30 07:13:15 +00:00
refactor: refactor unnecessary else
/ elif
when if
block has a return
statement
The use of `else` or `elif` becomes redundant and can be dropped if the last statement under the leading `if` / `elif` block is a `return` statement. In the case of an `elif` after `return`, it can be written as a separate `if` block. For `else` blocks after `return`, 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.
This commit is contained in:
parent
7b3d0cb1ae
commit
678a659dda
1 changed files with 2 additions and 2 deletions
|
@ -19,10 +19,10 @@ class Img(commands.Cog):
|
||||||
async def get_image_attachments(ctx):
|
async def get_image_attachments(ctx):
|
||||||
if ctx.message.attachments:
|
if ctx.message.attachments:
|
||||||
return ctx.message.attachments[0]
|
return ctx.message.attachments[0]
|
||||||
elif ctx.message.reference:
|
if ctx.message.reference:
|
||||||
if ctx.message.reference.resolved.attachments:
|
if ctx.message.reference.resolved.attachments:
|
||||||
return ctx.message.reference.resolved.attachments[0]
|
return ctx.message.reference.resolved.attachments[0]
|
||||||
elif (
|
if (
|
||||||
ctx.message.reference.resolved.embeds
|
ctx.message.reference.resolved.embeds
|
||||||
and ctx.message.reference.resolved.embeds[0].image
|
and ctx.message.reference.resolved.embeds[0].image
|
||||||
):
|
):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue