From caf1cb316ed18820f3239a285ef14bf45ef963a2 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 3 Nov 2021 12:57:32 -0700 Subject: typing: initial annotations on importers This commit just adds the type annotations, doesn't do fixes to code to make type checking pass. --- python/fatcat_tools/importers/chocula.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'python/fatcat_tools/importers/chocula.py') diff --git a/python/fatcat_tools/importers/chocula.py b/python/fatcat_tools/importers/chocula.py index 8d2a89b6..842c7853 100644 --- a/python/fatcat_tools/importers/chocula.py +++ b/python/fatcat_tools/importers/chocula.py @@ -1,4 +1,7 @@ +from typing import Any, Dict, List, Optional + import fatcat_openapi_client +from fatcat_openapi_client import ApiClient, ContainerEntity from .common import EntityImporter, clean @@ -12,7 +15,7 @@ class ChoculaImporter(EntityImporter): See guide for details on the many 'extra' fields used here. """ - def __init__(self, api, **kwargs): + def __init__(self, api: ApiClient, **kwargs) -> None: eg_desc = kwargs.get( "editgroup_description", @@ -22,7 +25,7 @@ class ChoculaImporter(EntityImporter): eg_extra["agent"] = eg_extra.get("agent", "fatcat_tools.ChoculaImporter") super().__init__(api, editgroup_description=eg_desc, editgroup_extra=eg_extra, **kwargs) - def want(self, raw_record): + def want(self, raw_record: Any) -> bool: if not raw_record.get("ident") and not raw_record.get("_known_issnl"): self.counts["skip-unknown-new-issnl"] += 1 return False @@ -30,7 +33,7 @@ class ChoculaImporter(EntityImporter): return True return False - def parse_record(self, row): + def parse_record(self, row: Dict[str, Any]) -> Optional[ContainerEntity]: """ row is a python dict (parsed from JSON). @@ -75,7 +78,7 @@ class ChoculaImporter(EntityImporter): elif "journal " in name.lower(): container_type = "journal" - ce = fatcat_openapi_client.ContainerEntity( + ce = ContainerEntity( issnl=row["issnl"], issnp=row["extra"].get("issnp"), issne=row["extra"].get("issne"), @@ -88,7 +91,7 @@ class ChoculaImporter(EntityImporter): ) return ce - def try_update(self, ce): + def try_update(self, ce: ContainerEntity) -> bool: existing = None if ce.ident: @@ -193,7 +196,7 @@ class ChoculaImporter(EntityImporter): # if we got this far, it's a bug raise NotImplementedError - def insert_batch(self, batch): + def insert_batch(self, batch: List[ContainerEntity]) -> None: self.api.create_container_auto_batch( fatcat_openapi_client.ContainerAutoBatch( editgroup=fatcat_openapi_client.Editgroup( -- cgit v1.2.3