aboutsummaryrefslogtreecommitdiffstats
path: root/python/fatcat_tools/importers/chocula.py
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2021-11-03 12:57:32 -0700
committerBryan Newbold <bnewbold@robocracy.org>2021-11-03 16:46:07 -0700
commitcaf1cb316ed18820f3239a285ef14bf45ef963a2 (patch)
tree2d3713773dac769878154f61c2eb9f7804f1a60c /python/fatcat_tools/importers/chocula.py
parent10a2374051568edf3d872988e730328d899a0fdd (diff)
downloadfatcat-caf1cb316ed18820f3239a285ef14bf45ef963a2.tar.gz
fatcat-caf1cb316ed18820f3239a285ef14bf45ef963a2.zip
typing: initial annotations on importers
This commit just adds the type annotations, doesn't do fixes to code to make type checking pass.
Diffstat (limited to 'python/fatcat_tools/importers/chocula.py')
-rw-r--r--python/fatcat_tools/importers/chocula.py15
1 files changed, 9 insertions, 6 deletions
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(