refactor: refactor unnecessary `else` / `elif` when `if` block has a `raise` statement

`raise` causes control flow to be disrupted, as it will exit the block.
It is recommended to check other conditions using another `if` statement, and get rid of `else` statements as they are unnecessary.
This commit is contained in:
deepsource-autofix[bot] 2023-08-06 23:03:35 +00:00 committed by GitHub
parent 36f2b87823
commit ed8a4755c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 18 deletions

View File

@ -19,21 +19,19 @@ class Config:
def token(self, token): def token(self, token):
if token is None: if token is None:
raise ValueError("No token provided") raise ValueError("No token provided")
else: url = "https://api.cloudflare.com/client/v4/user/tokens/verify"
url = "https://api.cloudflare.com/client/v4/user/tokens/verify" headers = {
headers = { "Authorization": f"Bearer {token}",
"Authorization": f"Bearer {token}", "Content-Type": "application/json",
"Content-Type": "application/json", }
} response = requests.get(url, headers=headers, timeout=10)
response = requests.get(url, headers=headers, timeout=10) if response.json()["success"] is False:
if response.json()["success"] is False: raise ValueError("Invalid token")
raise ValueError("Invalid token") # Token needs the following scopes:
else: # Zero Trust: Read/Edit
# Token needs the following scopes: # Account Firewall Access Rules: Read/Edit
# Zero Trust: Read/Edit # Access Apps and Policies: Read/Edit
# Account Firewall Access Rules: Read/Edit self._token = token
# Access Apps and Policies: Read/Edit
self._token = token
@property @property
def account_id(self): def account_id(self):
@ -43,9 +41,8 @@ class Config:
def account_id(self, account_id): def account_id(self, account_id):
if account_id is None: if account_id is None:
raise ValueError("No account ID provided") raise ValueError("No account ID provided")
else: # Possibly make a request to lists to check if the account ID exists
# Possibly make a request to lists to check if the account ID exists self._account_id = account_id
self._account_id = account_id
# List Utils # List Utils