Consider merging collapsible if statements
360 return render_redirect(url_for('account'))
361
362 # If there is a next destination, is it in the same domain as the client?
363 if 'next' in request.args:364 if not auth_client.host_matches(request.args['next']):
365 # Host doesn't match. Assume CSRF and redirect to account without logout
366 flash(LOGOUT_ERRORMSG, 'danger')
Consider merging collapsible if statements
292def autoset_timezone_and_locale() -> None:
293 """Set the current user's timezone and locale automatically if required."""
294 user = current_auth.user
295 if (296 user.auto_timezone
297 or not user.timezone
298 or str(user.timezone).lower() not in valid_timezones
Consider merging collapsible if statements
926 old_value: EmailAddress | None,
927 _initiator: Any,
928) -> None:
929 if value != old_value and target.__email_for__:930 if value is not None:
931 if value.is_blocked:
932 raise EmailAddressBlockedError("This email address has been blocked")
Description
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.
Bad practice
if condition1:
if condition2:
dosomething()
Preferred
if condition1 and condition2:
dosomething()
Exception:
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.