else
/ elif
used after return
PYL-R170513 """Deploys the function to GCP"""
14 service = function.config.deploy_variables.service
15
16 if service == GCPServices.CLOUD_FUNCTION:17 from .cloud_function.cli import deploy_function
18
19 return deploy_function(function)
24def describe(function: FunctionRecord) -> None:
25 """Use the `describe` command to retrieve information about a function"""
26 service = function.config.deploy_variables.service
27 if service == GCPServices.CLOUD_FUNCTION:28 from .cloud_function.cli import run_describe_cmd
29
30 return run_describe_cmd(function)
35def fetch_logs(function: FunctionRecord) -> None:
36 """Fetches the logs for the function"""
37 service = function.config.deploy_variables.service
38 if service == GCPServices.CLOUD_FUNCTION:39 from .cloud_function.cli import fetch_function_logs
40
41 return fetch_function_logs(function)
32 trigger_type: TriggerType, trigger_value: Optional[str] = None
33) -> List[str]:
34 """Returns a list of arguments to append that denote the type of trigger applied"""
35 if trigger_value: 36 return [trigger_type, trigger_value]
37 else:
38 return [trigger_type]
11) -> str:
12 """Validates the GCP deploy command"""
13 # Check if the function name is in the function registry
14 if FunctionRegistry.check_if_function_name_in_registry(function_name):15 return function_name
16 else:
17 raise typer.BadParameter(
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.
def classify_number(x):
if x % 2 == 0:
return 'Even'
else:
return 'Odd'
def what_is_this_number(x):
if x % 2 == 0 and x >= 0:
return 'Even'
elif x % 2 == 0 and x < 0:
return 'Even and Negative'
elif x % 2 != 0 and x < 0:
return 'Odd and Negative.'
else:
return 'Odd'
def classify_number(x):
if x % 2 == 0:
return 'Even'
return 'Odd'
def what_is_this_number(x):
if x % 2 == 0 and x >= 0:
return 'Even'
if x % 2 == 0 and x < 0:
return 'Even and Negative'
if x % 2 != 0 and x < 0:
return 'Odd and Negative'
return 'Odd'