ruff: Fix RSE102 Unnecessary parentheses on raised exception.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
63246e4369
commit
88ab78ee25
7 changed files with 17 additions and 17 deletions
|
@ -77,7 +77,7 @@ def get_url_gif_giphy(keyword: str, api_key: str) -> Union[int, str]:
|
||||||
try:
|
try:
|
||||||
gif_url = data.json()["data"]["images"]["original"]["url"]
|
gif_url = data.json()["data"]["images"]["original"]["url"]
|
||||||
except (TypeError, KeyError): # Usually triggered by no result in Giphy.
|
except (TypeError, KeyError): # Usually triggered by no result in Giphy.
|
||||||
raise GiphyNoResultException()
|
raise GiphyNoResultException
|
||||||
return gif_url
|
return gif_url
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -49,10 +49,10 @@ def make_API_request(
|
||||||
and r.json()["error"] == "Invalid API Authentication"
|
and r.json()["error"] == "Invalid API Authentication"
|
||||||
):
|
):
|
||||||
logging.error("Error authenticating, please check key " + str(r.url))
|
logging.error("Error authenticating, please check key " + str(r.url))
|
||||||
raise AuthenticationException()
|
raise AuthenticationException
|
||||||
else:
|
else:
|
||||||
logging.error("Error make API request, code " + str(r.status_code) + ". json: " + r.json())
|
logging.error("Error make API request, code " + str(r.status_code) + ". json: " + r.json())
|
||||||
raise UnspecifiedProblemException()
|
raise UnspecifiedProblemException
|
||||||
|
|
||||||
|
|
||||||
def api_noop() -> None:
|
def api_noop() -> None:
|
||||||
|
|
|
@ -63,7 +63,7 @@ def start_new_incident(query: str, message: Dict[str, Any], bot_handler: BotHand
|
||||||
def parse_answer(query: str) -> Tuple[str, str]:
|
def parse_answer(query: str) -> Tuple[str, str]:
|
||||||
m = re.match(r"answer\s+(TICKET....)\s+(.)", query)
|
m = re.match(r"answer\s+(TICKET....)\s+(.)", query)
|
||||||
if not m:
|
if not m:
|
||||||
raise InvalidAnswerException()
|
raise InvalidAnswerException
|
||||||
|
|
||||||
ticket_id = m.group(1)
|
ticket_id = m.group(1)
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ def parse_answer(query: str) -> Tuple[str, str]:
|
||||||
|
|
||||||
answer = m.group(2).upper()
|
answer = m.group(2).upper()
|
||||||
if answer not in "1234":
|
if answer not in "1234":
|
||||||
raise InvalidAnswerException()
|
raise InvalidAnswerException
|
||||||
|
|
||||||
return (ticket_id, ANSWERS[answer])
|
return (ticket_id, ANSWERS[answer])
|
||||||
|
|
||||||
|
|
|
@ -116,13 +116,13 @@ class MentionHandler:
|
||||||
alert_id = self.get_alert_id(keyword)
|
alert_id = self.get_alert_id(keyword)
|
||||||
except (TypeError, KeyError):
|
except (TypeError, KeyError):
|
||||||
# Usually triggered by invalid token or json parse error when account quote is finished.
|
# Usually triggered by invalid token or json parse error when account quote is finished.
|
||||||
raise MentionNoResponseException()
|
raise MentionNoResponseException
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mentions = self.get_mentions(alert_id)
|
mentions = self.get_mentions(alert_id)
|
||||||
except (TypeError, KeyError):
|
except (TypeError, KeyError):
|
||||||
# Usually triggered by no response or json parse error when account quota is finished.
|
# Usually triggered by no response or json parse error when account quota is finished.
|
||||||
raise MentionNoResponseException()
|
raise MentionNoResponseException
|
||||||
|
|
||||||
reply = "The most recent mentions of `" + keyword + "` on the web are: \n"
|
reply = "The most recent mentions of `" + keyword + "` on the web are: \n"
|
||||||
for mention in mentions:
|
for mention in mentions:
|
||||||
|
|
|
@ -75,12 +75,12 @@ def start_new_quiz(message: Dict[str, Any], bot_handler: BotHandler) -> None:
|
||||||
def parse_answer(query: str) -> Tuple[str, str]:
|
def parse_answer(query: str) -> Tuple[str, str]:
|
||||||
m = re.match(r"answer\s+(Q...)\s+(.)", query)
|
m = re.match(r"answer\s+(Q...)\s+(.)", query)
|
||||||
if not m:
|
if not m:
|
||||||
raise InvalidAnswerException()
|
raise InvalidAnswerException
|
||||||
|
|
||||||
quiz_id = m.group(1)
|
quiz_id = m.group(1)
|
||||||
answer = m.group(2).upper()
|
answer = m.group(2).upper()
|
||||||
if answer not in "ABCD":
|
if answer not in "ABCD":
|
||||||
raise InvalidAnswerException()
|
raise InvalidAnswerException
|
||||||
|
|
||||||
return (quiz_id, answer)
|
return (quiz_id, answer)
|
||||||
|
|
||||||
|
@ -98,10 +98,10 @@ def get_trivia_payload() -> Dict[str, Any]:
|
||||||
data = requests.get(url)
|
data = requests.get(url)
|
||||||
|
|
||||||
except requests.exceptions.RequestException:
|
except requests.exceptions.RequestException:
|
||||||
raise NotAvailableException()
|
raise NotAvailableException
|
||||||
|
|
||||||
if data.status_code != 200:
|
if data.status_code != 200:
|
||||||
raise NotAvailableException()
|
raise NotAvailableException
|
||||||
|
|
||||||
payload = data.json()
|
payload = data.json()
|
||||||
return payload
|
return payload
|
||||||
|
|
|
@ -104,7 +104,7 @@ def fetch_xkcd_query(mode: int, comic_id: Optional[str] = None) -> Dict[str, str
|
||||||
latest = requests.get(LATEST_XKCD_URL)
|
latest = requests.get(LATEST_XKCD_URL)
|
||||||
|
|
||||||
if latest.status_code != 200:
|
if latest.status_code != 200:
|
||||||
raise XkcdServerError()
|
raise XkcdServerError
|
||||||
|
|
||||||
latest_id = latest.json()["num"]
|
latest_id = latest.json()["num"]
|
||||||
random_id = random.randint(1, latest_id)
|
random_id = random.randint(1, latest_id)
|
||||||
|
@ -118,9 +118,9 @@ def fetch_xkcd_query(mode: int, comic_id: Optional[str] = None) -> Dict[str, str
|
||||||
fetched = requests.get(url)
|
fetched = requests.get(url)
|
||||||
|
|
||||||
if fetched.status_code == 404:
|
if fetched.status_code == 404:
|
||||||
raise XkcdNotFoundError()
|
raise XkcdNotFoundError
|
||||||
elif fetched.status_code != 200:
|
elif fetched.status_code != 200:
|
||||||
raise XkcdServerError()
|
raise XkcdServerError
|
||||||
|
|
||||||
xkcd_json = fetched.json()
|
xkcd_json = fetched.json()
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
|
|
|
@ -51,7 +51,7 @@ class StubBotHandler:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def quit(self, message: str = "") -> None:
|
def quit(self, message: str = "") -> None:
|
||||||
raise self.BotQuitException()
|
raise self.BotQuitException
|
||||||
|
|
||||||
def get_config_info(self, bot_name: str, optional: bool = False) -> Dict[str, str]:
|
def get_config_info(self, bot_name: str, optional: bool = False) -> Dict[str, str]:
|
||||||
return {}
|
return {}
|
||||||
|
@ -77,10 +77,10 @@ class DefaultTests:
|
||||||
bot_name = ""
|
bot_name = ""
|
||||||
|
|
||||||
def make_request_message(self, content: str) -> Dict[str, Any]:
|
def make_request_message(self, content: str) -> Dict[str, Any]:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError
|
||||||
|
|
||||||
def get_response(self, message: Dict[str, Any]) -> Dict[str, Any]:
|
def get_response(self, message: Dict[str, Any]) -> Dict[str, Any]:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError
|
||||||
|
|
||||||
def test_bot_usage(self) -> None:
|
def test_bot_usage(self) -> None:
|
||||||
bot = get_bot_message_handler(self.bot_name)
|
bot = get_bot_message_handler(self.bot_name)
|
||||||
|
|
Loading…
Add table
Reference in a new issue