mirror of
https://github.com/pyMC-dev/pyMC_Repeater.git
synced 2026-06-28 05:52:02 +02:00
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:
@@ -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
|
||||
|
||||
@@ -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 — "
|
||||
|
||||
Reference in New Issue
Block a user