From 20a972a014b9baf7352654f68ed91cfe3bbbc72e Mon Sep 17 00:00:00 2001 From: null8626 Date: Sat, 28 Sep 2024 19:19:26 +0700 Subject: [PATCH 1/3] refactor: enable raise_for_status --- python_weather/client.py | 1 + python_weather/forecast.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/python_weather/client.py b/python_weather/client.py index ea4d1de..670df0c 100644 --- a/python_weather/client.py +++ b/python_weather/client.py @@ -37,6 +37,7 @@ def __init__( super().__init__(unit, locale) self.__session = session or ClientSession( + raise_for_status=True, timeout=ClientTimeout(total=5000.0), connector=TCPConnector(verify_ssl=False), ) diff --git a/python_weather/forecast.py b/python_weather/forecast.py index fad2278..f4db52d 100644 --- a/python_weather/forecast.py +++ b/python_weather/forecast.py @@ -312,5 +312,5 @@ def coordinates(self) -> Tuple[float, float]: match = LATLON_REGEX.match(req['query']) return float(match[1]), float(match[2]) - except Exception: + except: return float(self.__nearest['latitude']), float(self.__nearest['longitude']) From 151d48d9e6a711398c2fe07e4df19af98427e202 Mon Sep 17 00:00:00 2001 From: null8626 Date: Sat, 28 Sep 2024 19:23:15 +0700 Subject: [PATCH 2/3] refactor: use __class__ directly --- python_weather/client.py | 2 +- python_weather/enums.py | 2 +- python_weather/forecast.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/python_weather/client.py b/python_weather/client.py index 670df0c..40dab63 100644 --- a/python_weather/client.py +++ b/python_weather/client.py @@ -43,7 +43,7 @@ def __init__( ) def __repr__(self) -> str: - return f'<{self.__class__.__name__} {self.__session!r}>' + return f'<{__class__.__name__} {self.__session!r}>' async def get( self, diff --git a/python_weather/enums.py b/python_weather/enums.py index 8ee8ac6..ff499de 100644 --- a/python_weather/enums.py +++ b/python_weather/enums.py @@ -267,7 +267,7 @@ class Locale(Enum): ZULU = 'zu' def __repr__(self) -> str: - return f'{self.__class__.__name__}.{self.name}' + return f'{__class__.__name__}.{self.name}' def __str__(self) -> str: arr = self.name.title().split('_') diff --git a/python_weather/forecast.py b/python_weather/forecast.py index f4db52d..508a513 100644 --- a/python_weather/forecast.py +++ b/python_weather/forecast.py @@ -21,7 +21,7 @@ def __init__(self, json: dict, unit: _Unit, locale: Locale): super().__init__(json, unit, locale) def __repr__(self) -> str: - return f'<{self.__class__.__name__} time={self.time!r} temperature={self.temperature!r} description={self.description!r} kind={self.kind!r}>' + return f'<{__class__.__name__} time={self.time!r} temperature={self.temperature!r} description={self.description!r} kind={self.kind!r}>' @property def dew_point(self) -> int: @@ -150,7 +150,7 @@ def __init__(self, json: dict, unit: _Unit, locale: Locale): def __repr__(self) -> str: return ( - f'<{self.__class__.__name__} date={self.date!r} temperature={self.temperature!r}>' + f'<{__class__.__name__} date={self.date!r} temperature={self.temperature!r}>' ) @property @@ -260,7 +260,7 @@ def __init__(self, json: dict, unit: _Unit, locale: Locale): super().__init__(current, unit, locale) def __repr__(self) -> str: - return f'<{self.__class__.__name__} location={self.location!r} datetime={self.datetime!r} temperature={self.temperature!r}>' + return f'<{__class__.__name__} location={self.location!r} datetime={self.datetime!r} temperature={self.temperature!r}>' @property def local_population(self) -> int: From e6cbb18317e6dcb9d1ca8988f0bc7272409ec455 Mon Sep 17 00:00:00 2001 From: null8626 Date: Sat, 28 Sep 2024 12:23:35 +0000 Subject: [PATCH 3/3] style: prettier --- python_weather/forecast.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/python_weather/forecast.py b/python_weather/forecast.py index 508a513..ed80836 100644 --- a/python_weather/forecast.py +++ b/python_weather/forecast.py @@ -149,9 +149,7 @@ def __init__(self, json: dict, unit: _Unit, locale: Locale): super().__init__(unit, locale) def __repr__(self) -> str: - return ( - f'<{__class__.__name__} date={self.date!r} temperature={self.temperature!r}>' - ) + return f'<{__class__.__name__} date={self.date!r} temperature={self.temperature!r}>' @property def moon_illumination(self) -> int: