fix: resolve remaining ruff lint and mypy type errors

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Justin Visser 2026-02-26 22:58:55 +01:00
parent bf04c77aa9
commit ac002131d6
24 changed files with 219 additions and 57 deletions

View file

@ -109,6 +109,9 @@ def _classify_failure_bucket(*, state: str, state_reason: str) -> str:
return FAILURE_BUCKET_OTHER
_background_tasks: set[asyncio.Task[Any]] = set()
class ScholarIngestionService:
def __init__(self, *, source: ScholarSource) -> None:
self._source = source
@ -287,9 +290,8 @@ class ScholarIngestionService:
paged_parse_result: PagedParseResult,
) -> None:
parsed_page = paged_parse_result.parsed_page
if parsed_page.state in {ParseState.OK, ParseState.NO_RESULTS}:
if any(code.startswith("layout_") for code in parsed_page.warnings):
raise RuntimeError(f"Layout warning marked as terminal for scholar_id={scholar_id}.")
if parsed_page.state in {ParseState.OK, ParseState.NO_RESULTS} and any(code.startswith("layout_") for code in parsed_page.warnings):
raise RuntimeError(f"Layout warning marked as terminal for scholar_id={scholar_id}.")
for publication in paged_parse_result.publications:
if not publication.title.strip():
raise RuntimeError(f"Malformed publication title for scholar_id={scholar_id}.")
@ -1490,7 +1492,7 @@ class ScholarIngestionService:
# Fire-and-forget enrichment in a separate background task
if intended_final_status not in (RunStatus.CANCELED,):
asyncio.create_task(
task = asyncio.create_task(
self._background_enrich(
session_factory,
run_id=run.id,
@ -1498,6 +1500,8 @@ class ScholarIngestionService:
openalex_api_key=getattr(user_settings, "openalex_api_key", None),
)
)
_background_tasks.add(task)
task.add_done_callback(_background_tasks.discard)
except Exception as exc:
await db_session.rollback()
logger.exception("ingestion.background_run_failed", extra={"run_id": run_id, "user_id": user_id})
@ -2807,7 +2811,7 @@ class ScholarIngestionService:
publication.venue_text = candidate.venue_text
if candidate.title_url:
publication.pub_url = build_publication_url(candidate.title_url)
local_doi = first_doi_from_texts(candidate.title_url, candidate.venue_text, candidate.title)
first_doi_from_texts(candidate.title_url, candidate.venue_text, candidate.title)
async def _resolve_publication(
self,

View file

@ -367,10 +367,7 @@ def _publication_identity(pub: PublicationCandidate) -> str:
def _is_fuzzy_dup(tokens: set[str], seen: list[set[str]]) -> bool:
for existing in seen:
if _jaccard(tokens, existing) >= _CANONICAL_DEDUP_THRESHOLD:
return True
return False
return any(_jaccard(tokens, existing) >= _CANONICAL_DEDUP_THRESHOLD for existing in seen)
def _build_body_excerpt(body: str, *, max_chars: int = 220) -> str | None:

View file

@ -330,9 +330,7 @@ class SchedulerService:
await session.commit()
if queue_item is None:
return False
if queue_item.status == QueueItemStatus.DROPPED.value:
return False
return True
return queue_item.status != QueueItemStatus.DROPPED.value
async def _queue_job_has_available_scholar(
self,