From df1194ee965668699e0948d12944c1d3767342fe Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Wed, 25 Mar 2026 14:59:05 -0400 Subject: [PATCH] fix(tools): remove duplicate datetime import in get_weather handler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The local `from datetime import datetime, timezone as _tz` inside execute_tool() shadowed the module-level datetime import for the entire function scope, causing UnboundLocalError in all calendar tool handlers (list_events, create_event, update_event). Fixed by importing only timezone as _tz — datetime is already available at module level. Also removes the now-unnecessary noqa: F823 suppression. Co-Authored-By: Claude Sonnet 4.6 --- src/fabledassistant/services/tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fabledassistant/services/tools.py b/src/fabledassistant/services/tools.py index 22f7b02..f9b28da 100644 --- a/src/fabledassistant/services/tools.py +++ b/src/fabledassistant/services/tools.py @@ -1238,7 +1238,7 @@ async def execute_tool(user_id: int, tool_name: str, arguments: dict) -> dict: all_day = True start_str = f"{start_str}T00:00:00" try: - start_dt = datetime.fromisoformat(start_str) # noqa: F823 (false positive — datetime is imported at module level) + start_dt = datetime.fromisoformat(start_str) except (ValueError, TypeError): return {"success": False, "error": f"Invalid start datetime: {start_str!r}"} end_dt = None @@ -1705,7 +1705,7 @@ async def execute_tool(user_id: int, tool_name: str, arguments: dict) -> dict: from fabledassistant.services.weather import ( get_cached_weather, geocode, _fetch_open_meteo, parse_forecast ) - from datetime import datetime, timezone as _tz + from datetime import timezone as _tz location = (arguments.get("location") or "").strip() _known = {"home", "work", "all", ""} if location.lower() not in _known: