From 237a8cbb3898ea6df769a2fe9f8589f45efaea06 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Tue, 9 Jan 2024 21:06:00 +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/plugins/nonebot_plugin_heweather/weather_data.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/plugins/nonebot_plugin_heweather/weather_data.py b/src/plugins/nonebot_plugin_heweather/weather_data.py index 01c0c18..9572fc6 100644 --- a/src/plugins/nonebot_plugin_heweather/weather_data.py +++ b/src/plugins/nonebot_plugin_heweather/weather_data.py @@ -84,11 +84,10 @@ async def _get_city_id(self, api_type: str = "lookup"): logger.debug(res) if res["code"] == "404": raise CityNotFoundError() - elif res["code"] != "200": + if res["code"] != "200": raise APIError(f'错误! 错误代码: {res["code"]}{self.__reference}') - else: - self.city_name = res["location"][0]["name"] - return res["location"][0]["id"] + self.city_name = res["location"][0]["name"] + return res["location"][0]["id"] def _data_validate(self): if self.now.code != "200" or self.daily.code != "200":