From d597ab2ea8dac5aa3d8ccf6b68a56c1c53b0f0a0 Mon Sep 17 00:00:00 2001 From: Zindello Date: Wed, 27 May 2026 12:12:56 +1000 Subject: [PATCH] fix: replace datetime.UTC attribute access in repeater_cli Also extend the compat scanner to catch datetime.UTC used as an attribute (datetime.datetime.now(datetime.UTC)) in addition to direct imports, so this form cannot be reintroduced undetected. Co-Authored-By: Zindello --- repeater/handler_helpers/repeater_cli.py | 2 +- tests/test_python310_compat.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/repeater/handler_helpers/repeater_cli.py b/repeater/handler_helpers/repeater_cli.py index 278a052..e2f993b 100644 --- a/repeater/handler_helpers/repeater_cli.py +++ b/repeater/handler_helpers/repeater_cli.py @@ -285,7 +285,7 @@ class MeshCLI: # Display current time import datetime - dt = datetime.datetime.now(datetime.UTC) + dt = datetime.datetime.now(datetime.timezone.utc) return f"{dt.hour:02d}:{dt.minute:02d} - {dt.day}/{dt.month}/{dt.year} UTC" elif command == "clock sync": # Clock sync happens automatically via sender_timestamp in protocol diff --git a/tests/test_python310_compat.py b/tests/test_python310_compat.py index 6d90e17..5edc44f 100644 --- a/tests/test_python310_compat.py +++ b/tests/test_python310_compat.py @@ -32,10 +32,20 @@ def test_no_datetime_utc(): except SyntaxError: continue for node in ast.walk(tree): + # catch: from datetime import UTC if isinstance(node, ast.ImportFrom) and node.module == "datetime": if any(alias.name == "UTC" for alias in node.names): rel = path.relative_to(_REPEATER_ROOT.parent) violations.append(f" {rel}:{node.lineno}") + # catch: datetime.UTC + if ( + isinstance(node, ast.Attribute) + and node.attr == "UTC" + and isinstance(node.value, ast.Name) + and node.value.id == "datetime" + ): + rel = path.relative_to(_REPEATER_ROOT.parent) + violations.append(f" {rel}:{node.lineno}") assert not violations, ( "datetime.UTC (Python 3.11+) found in the following files — "