Canonical: fix ruff lint (B023 loop-bound lambda, S110 bare except-pass)
- B023: default_fetch_tracklist built a per-item lambda closing over the loop variable `it`. Replaced with a module-level _item_get(item, key, default) helper (takes the item as a param — no closure). Behavior unchanged; the dict/object normalization test still passes. - S110: the two best-effort guards in the canonical job (skip-already-pinned read, estimate_scope active-server read) now carry `# noqa: S110 — <reason>`, matching the repo's existing convention for intentional swallow-and-continue. ruff check passes on all canonical files + tests; 30 affected tests green.
This commit is contained in:
parent
dfa5204e0a
commit
eaf74732f9
2 changed files with 11 additions and 7 deletions
|
|
@ -138,6 +138,11 @@ def resolve_canonical_for_album(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _item_get(item: Any, key: str, default: Any = None) -> Any:
|
||||||
|
"""Read ``key`` from a track item that may be a dict or an object."""
|
||||||
|
return item.get(key, default) if isinstance(item, dict) else getattr(item, key, default)
|
||||||
|
|
||||||
|
|
||||||
def default_fetch_tracklist(source: str, album_id: str) -> Optional[List[Dict[str, Any]]]:
|
def default_fetch_tracklist(source: str, album_id: str) -> Optional[List[Dict[str, Any]]]:
|
||||||
"""Production ``fetch_tracklist``: pull a release's tracklist from a metadata
|
"""Production ``fetch_tracklist``: pull a release's tracklist from a metadata
|
||||||
source and normalise to ``{title, track_number, duration_ms}``. Duration is
|
source and normalise to ``{title, track_number, duration_ms}``. Duration is
|
||||||
|
|
@ -155,14 +160,13 @@ def default_fetch_tracklist(source: str, album_id: str) -> Optional[List[Dict[st
|
||||||
items = items.get('items') or []
|
items = items.get('items') or []
|
||||||
out: List[Dict[str, Any]] = []
|
out: List[Dict[str, Any]] = []
|
||||||
for it in items:
|
for it in items:
|
||||||
get = it.get if isinstance(it, dict) else (lambda k, d=None: getattr(it, k, d))
|
dur = _item_get(it, 'duration_ms')
|
||||||
dur = get('duration_ms')
|
|
||||||
if dur is None:
|
if dur is None:
|
||||||
secs = get('duration') # some sources give seconds
|
secs = _item_get(it, 'duration') # some sources give seconds
|
||||||
dur = int(secs * 1000) if isinstance(secs, (int, float)) and secs else None
|
dur = int(secs * 1000) if isinstance(secs, (int, float)) and secs else None
|
||||||
out.append({
|
out.append({
|
||||||
'title': get('name') or get('title') or '',
|
'title': _item_get(it, 'name') or _item_get(it, 'title') or '',
|
||||||
'track_number': get('track_number'),
|
'track_number': _item_get(it, 'track_number'),
|
||||||
'duration_ms': dur,
|
'duration_ms': dur,
|
||||||
})
|
})
|
||||||
return out or None
|
return out or None
|
||||||
|
|
|
||||||
|
|
@ -168,7 +168,7 @@ class CanonicalVersionResolveJob(RepairJob):
|
||||||
result.skipped += 1
|
result.skipped += 1
|
||||||
result.scanned += 1
|
result.scanned += 1
|
||||||
continue
|
continue
|
||||||
except Exception:
|
except Exception: # noqa: S110 — best-effort skip check; on read error just resolve it
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -216,6 +216,6 @@ class CanonicalVersionResolveJob(RepairJob):
|
||||||
if context.config_manager:
|
if context.config_manager:
|
||||||
try:
|
try:
|
||||||
active_server = context.config_manager.get_active_media_server()
|
active_server = context.config_manager.get_active_media_server()
|
||||||
except Exception:
|
except Exception: # noqa: S110 — best-effort; fall back to no server filter
|
||||||
pass
|
pass
|
||||||
return len(self._load_album_ids(context.db, active_server))
|
return len(self._load_album_ids(context.db, active_server))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue