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 <josh@zindello.com.au>
This commit is contained in:
Zindello
2026-05-27 12:12:56 +10:00
parent a1c66100f5
commit d597ab2ea8
2 changed files with 11 additions and 1 deletions
+10
View File
@@ -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 — "