22Location service for handling location searches and operations
33"""
44
5- from typing import TYPE_CHECKING , Any
5+ from typing import TYPE_CHECKING , Any , cast
66
77from loguru import logger
88
@@ -19,7 +19,9 @@ def __init__(self, weather_client: "NationalWeatherServiceClient"):
1919 self .weather_client = weather_client
2020
2121 @track_api_request ("search_locations" , "GET" )
22- async def search_locations (self , query : str , language : str = "en-us" ) -> dict [str , Any ]:
22+ async def search_locations (
23+ self , query : str , language : str = "en-us"
24+ ) -> dict [str , Any ]:
2325 """Search for weather locations by name or ZIP code"""
2426 try :
2527 results = await self .weather_client .search_locations (query , language )
@@ -28,7 +30,9 @@ async def search_locations(self, query: str, language: str = "en-us") -> dict[st
2830 logger .error (f"Location search failed: { e } " )
2931 return {"success" : False , "error" : str (e )}
3032
31- async def get_location_weather (self , query : str , language : str = "en-us" ) -> dict [str , Any ]:
33+ async def get_location_weather (
34+ self , query : str , language : str = "en-us"
35+ ) -> dict [str , Any ]:
3236 """Get current weather by searching for a location first"""
3337 try :
3438 from .weather_service import WeatherService
@@ -46,7 +50,7 @@ async def get_location_weather(self, query: str, language: str = "en-us") -> dic
4650 )
4751
4852 if not weather_result ["success" ]:
49- return weather_result
53+ return cast ( dict [ str , Any ], weather_result )
5054
5155 return {
5256 "success" : True ,
@@ -57,7 +61,9 @@ async def get_location_weather(self, query: str, language: str = "en-us") -> dic
5761 logger .error (f"Location weather failed: { e } " )
5862 return {"success" : False , "error" : str (e )}
5963
60- async def get_location_forecast (self , query : str , language : str = "en-us" ) -> dict [str , Any ]:
64+ async def get_location_forecast (
65+ self , query : str , language : str = "en-us"
66+ ) -> dict [str , Any ]:
6167 """Get 5-day forecast by searching for a location first"""
6268 try :
6369 from .forecast_service import ForecastService
@@ -75,7 +81,7 @@ async def get_location_forecast(self, query: str, language: str = "en-us") -> di
7581 )
7682
7783 if not forecast_result ["success" ]:
78- return forecast_result
84+ return cast ( dict [ str , Any ], forecast_result )
7985
8086 return {
8187 "success" : True ,
@@ -87,7 +93,9 @@ async def get_location_forecast(self, query: str, language: str = "en-us") -> di
8793 logger .error (f"Location forecast failed: { e } " )
8894 return {"success" : False , "error" : str (e )}
8995
90- async def get_location_alerts (self , query : str , language : str = "en-us" ) -> dict [str , Any ]:
96+ async def get_location_alerts (
97+ self , query : str , language : str = "en-us"
98+ ) -> dict [str , Any ]:
9199 """Get weather alerts by searching for a location first"""
92100 try :
93101 from .alert_service import AlertService
@@ -103,7 +111,7 @@ async def get_location_alerts(self, query: str, language: str = "en-us") -> dict
103111 alert_result = await alert_service .get_weather_alerts (location_key )
104112
105113 if not alert_result ["success" ]:
106- return alert_result
114+ return cast ( dict [ str , Any ], alert_result )
107115
108116 return {
109117 "success" : True ,
0 commit comments