From 76baee76235267c133f8974138af8320ce962016 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Mon, 6 Apr 2026 14:09:58 +0000 Subject: [PATCH] fix(coordinator): move timedelta import out of while loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PLC0415 – suppress with noqa was already suppressing the warning, but the import was still executed on every iteration of the while loop. Standard library imports belong at module level both for correctness and performance. Move 'from datetime import timedelta' to the top-level import block and remove the now-unnecessary 'noqa: PLC0415' comment. Impact: Negligible per-call overhead removed. More importantly, the code no longer suppresses a linter warning that signals a real anti-pattern; future static analysis runs will correctly flag any new inline imports. --- .../tibber_prices/coordinator/period_handlers/relaxation.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/custom_components/tibber_prices/coordinator/period_handlers/relaxation.py b/custom_components/tibber_prices/coordinator/period_handlers/relaxation.py index 695d8d9..41c7aa5 100644 --- a/custom_components/tibber_prices/coordinator/period_handlers/relaxation.py +++ b/custom_components/tibber_prices/coordinator/period_handlers/relaxation.py @@ -217,11 +217,6 @@ def group_periods_by_day(periods: list[dict]) -> dict[date, list[dict]]: while current_date <= end_date: periods_by_day.setdefault(current_date, []).append(period) # Move to next day - from datetime import timedelta # noqa: PLC0415 - - current_date = current_date + timedelta(days=1) - - return periods_by_day def mark_periods_with_relaxation(