elif
/ else
block after continue
PYL-R1724561 for auth in auth_settings:
562 auth_setting = self.configuration.auth_settings().get(auth)
563 if auth_setting:
564 if not auth_setting["value"]:565 continue
566 elif auth_setting["in"] == "header":
567 headers[auth_setting["key"]] = auth_setting["value"]
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}")