From ed8a4755c1d056f43227e2faee55581a6c5b934b Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Sun, 6 Aug 2023 23:03:35 +0000 Subject: [PATCH] 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. --- src/utils/utils.py | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/utils/utils.py b/src/utils/utils.py index c38071f..3d9c2a8 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -19,21 +19,19 @@ class Config: def token(self, token): if token is None: raise ValueError("No token provided") - else: - url = "https://api.cloudflare.com/client/v4/user/tokens/verify" - headers = { - "Authorization": f"Bearer {token}", - "Content-Type": "application/json", - } - response = requests.get(url, headers=headers, timeout=10) - if response.json()["success"] is False: - raise ValueError("Invalid token") - else: - # Token needs the following scopes: - # Zero Trust: Read/Edit - # Account Firewall Access Rules: Read/Edit - # Access Apps and Policies: Read/Edit - self._token = token + url = "https://api.cloudflare.com/client/v4/user/tokens/verify" + headers = { + "Authorization": f"Bearer {token}", + "Content-Type": "application/json", + } + response = requests.get(url, headers=headers, timeout=10) + if response.json()["success"] is False: + raise ValueError("Invalid token") + # Token needs the following scopes: + # Zero Trust: Read/Edit + # Account Firewall Access Rules: Read/Edit + # Access Apps and Policies: Read/Edit + self._token = token @property def account_id(self): @@ -43,9 +41,8 @@ class Config: def account_id(self, account_id): if account_id is None: raise ValueError("No account ID provided") - else: - # Possibly make a request to lists to check if the account ID exists - self._account_id = account_id + # Possibly make a request to lists to check if the account ID exists + self._account_id = account_id # List Utils