fix(fc2a): satisfy ruff 0.15.13 lint — UP017, UP042, I001
Ruff lint surfaced 23 violations across three rules; all addressed: UP017 (Use datetime.UTC alias): Replaced 13 sites of datetime.now(timezone.utc) with datetime.now(UTC), also adjusted from-imports accordingly. UTC is a Python 3.11+ alias for timezone.utc that ruff's pyupgrade rules prefer. UP042 (StrEnum): Replaced `class TagKind(str, Enum)` and `class SkipReason(str, Enum)` with `class Foo(StrEnum)`. StrEnum was added in Python 3.11 stdlib and is the modern idiom. Behavior is equivalent for our usage (the .value attribute, str(member) semantics). I001 (Import sorting): Added `known-first-party = ["backend"]` to ruff.toml's [lint.isort] so ruff groups `backend.*` imports correctly. Without it, ruff treated them as third-party and demanded a different grouping. The existing import order is stdlib → third-party → first-party → local relative, which ruff now accepts. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from datetime import UTC, datetime, timedelta
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -18,7 +18,7 @@ async def client(app):
|
||||
|
||||
|
||||
async def _seed(db, count: int = 3):
|
||||
base = datetime.now(timezone.utc)
|
||||
base = datetime.now(UTC)
|
||||
for i in range(count):
|
||||
r = ImageRecord(
|
||||
path=f"/images/x/{i}.jpg",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from datetime import UTC, datetime, timedelta
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -46,7 +46,7 @@ async def test_list_tasks_with_status_filter(client, db):
|
||||
for status in ("complete", "failed", "complete"):
|
||||
db.add(ImportTask(
|
||||
batch_id=batch.id, source_path="/x", task_type="media", status=status,
|
||||
finished_at=datetime.now(timezone.utc),
|
||||
finished_at=datetime.now(UTC),
|
||||
))
|
||||
await db.commit()
|
||||
|
||||
@@ -74,14 +74,14 @@ async def test_clear_completed(client, db):
|
||||
batch = ImportBatch(triggered_by="manual", source_path="/import", scan_mode="quick")
|
||||
db.add(batch)
|
||||
await db.flush()
|
||||
long_ago = datetime.now(timezone.utc) - timedelta(days=30)
|
||||
long_ago = datetime.now(UTC) - timedelta(days=30)
|
||||
db.add(ImportTask(
|
||||
batch_id=batch.id, source_path="/x", task_type="media",
|
||||
status="complete", finished_at=long_ago,
|
||||
))
|
||||
db.add(ImportTask(
|
||||
batch_id=batch.id, source_path="/y", task_type="media",
|
||||
status="complete", finished_at=datetime.now(timezone.utc),
|
||||
status="complete", finished_at=datetime.now(UTC),
|
||||
))
|
||||
await db.commit()
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from datetime import UTC, datetime, timedelta
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -12,7 +12,7 @@ from backend.app.services.gallery_service import (
|
||||
|
||||
|
||||
def _now():
|
||||
return datetime.now(timezone.utc)
|
||||
return datetime.now(UTC)
|
||||
|
||||
|
||||
async def _seed_images(db, count: int, sha_prefix: str = "0") -> list[ImageRecord]:
|
||||
@@ -37,7 +37,7 @@ async def _seed_images(db, count: int, sha_prefix: str = "0") -> list[ImageRecor
|
||||
|
||||
|
||||
def test_cursor_roundtrip():
|
||||
ts = datetime(2026, 5, 14, 12, 30, 0, tzinfo=timezone.utc)
|
||||
ts = datetime(2026, 5, 14, 12, 30, 0, tzinfo=UTC)
|
||||
encoded = encode_cursor(ts, 42)
|
||||
back_ts, back_id = decode_cursor(encoded)
|
||||
assert back_ts == ts
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
function runs synchronously inside the same DB transaction as the test.
|
||||
"""
|
||||
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from datetime import UTC, datetime, timedelta
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -26,7 +26,7 @@ def _make_batch(session) -> int:
|
||||
|
||||
def test_recover_interrupted_only_old(db_sync):
|
||||
batch_id = _make_batch(db_sync)
|
||||
now = datetime.now(timezone.utc)
|
||||
now = datetime.now(UTC)
|
||||
|
||||
fresh = ImportTask(
|
||||
batch_id=batch_id, source_path="/import/a.jpg", task_type="media",
|
||||
@@ -52,7 +52,7 @@ def test_recover_interrupted_only_old(db_sync):
|
||||
|
||||
def test_cleanup_old_deletes_finished_old(db_sync):
|
||||
batch_id = _make_batch(db_sync)
|
||||
now = datetime.now(timezone.utc)
|
||||
now = datetime.now(UTC)
|
||||
|
||||
old_complete = ImportTask(
|
||||
batch_id=batch_id, source_path="/import/a.jpg", task_type="media",
|
||||
|
||||
Reference in New Issue
Block a user