fix: resolve pyright errors in processing modules

- add Abstract type annotation and import in metadata.py
- add type annotations for list variables to fix unknown append types
- fix is_doi return type by wrapping with bool() in validation.py

All tests continue to pass and type checking is now clean
across all processing and validation modules.
This commit is contained in:
Alexander Minges 2025-07-25 09:21:08 +02:00
parent e003592430
commit 34c81750ce
Signed by: Athemis
SSH key fingerprint: SHA256:TUXshgulbwL+FRYvBNo54pCsI0auROsSEgSvueKbkZ4
4 changed files with 12 additions and 9 deletions

View file

@ -6,12 +6,15 @@ including license processing and abstract extraction/cleaning.
""" """
import re import re
from typing import Any from typing import TYPE_CHECKING, Any
from rich.console import Console from rich.console import Console
from ..core.models import Abstract, License from ..core.models import Abstract, License
if TYPE_CHECKING:
from .client import APIClient
class LicenseProcessor: class LicenseProcessor:
""" """
@ -68,12 +71,12 @@ class AbstractProcessor:
# Icons for console output - TODO: should be moved to a constants module # Icons for console output - TODO: should be moved to a constants module
ICONS = {"info": "", "warning": "⚠️", "error": ""} ICONS = {"info": "", "warning": "⚠️", "error": ""}
def __init__(self, api_client, console: Console | None = None): def __init__(self, api_client: "APIClient", console: Console | None = None):
""" """
Initialize with an APIClient instance. Initialize with an APIClient instance.
Args: Args:
api_client: The API client to use for requests. api_client (APIClient): The API client to use for requests.
console (Console | None): Rich console instance for output. console (Console | None): Rich console instance for output.
""" """
self.api_client = api_client self.api_client = api_client

View file

@ -21,7 +21,7 @@ from ..core.metadata_fields import (
ControlledVocabularyMetadataField, ControlledVocabularyMetadataField,
PrimitiveMetadataField, PrimitiveMetadataField,
) )
from ..core.models import Person from ..core.models import Abstract, Person
from ..processing.citation import CitationBuilder from ..processing.citation import CitationBuilder
from ..processing.utils import NameProcessor, PIFinder, SubjectMapper from ..processing.utils import NameProcessor, PIFinder, SubjectMapper
@ -335,13 +335,13 @@ class MetadataProcessor:
return return_dict return return_dict
def _build_description(self, data: dict[str, Any], abstract) -> str: def _build_description(self, data: dict[str, Any], abstract: Abstract) -> str:
""" """
Build the description field by combining a header and the abstract. Build the description field by combining a header and the abstract.
Args: Args:
data (dict[str, Any]): The metadata. data (dict[str, Any]): The metadata.
abstract: The abstract object. abstract (Abstract): The abstract object.
Returns: Returns:
str: The full description. str: The full description.
@ -404,7 +404,7 @@ class MetadataProcessor:
list[Person]: List of matching PIs for use as corresponding authors. list[Person]: List of matching PIs for use as corresponding authors.
""" """
involved_pis: list[Person] = [] involved_pis: list[Person] = []
authors_in_publication = [] authors_in_publication: list[Person] = []
# Build list of authors from publication # Build list of authors from publication
for authorship in data.get("authorships", []): for authorship in data.get("authorships", []):

View file

@ -223,7 +223,7 @@ class SubjectMapper:
Returns: Returns:
list[str]: List of mapped controlled vocabulary terms. list[str]: List of mapped controlled vocabulary terms.
""" """
mapped = [] mapped: list[str] = []
for subject in subjects: for subject in subjects:
# Try exact match first # Try exact match first
if subject in cls.CONTROLLED_VOCAB: if subject in cls.CONTROLLED_VOCAB:

View file

@ -29,7 +29,7 @@ def validate_doi(doi: str) -> bool:
Returns: Returns:
bool: True if the DOI is valid, False otherwise. bool: True if the DOI is valid, False otherwise.
""" """
return is_doi(doi) return bool(is_doi(doi))
def normalize_doi(doi: str) -> str: def normalize_doi(doi: str) -> str: