aboutsummaryrefslogtreecommitdiffstats
path: root/python/fatcat_tools/importers/matched.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/matched.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/matched.py')
-rw-r--r--python/fatcat_tools/importers/matched.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/python/fatcat_tools/importers/matched.py b/python/fatcat_tools/importers/matched.py
index 7c2a6a87..9c80dd72 100644
--- a/python/fatcat_tools/importers/matched.py
+++ b/python/fatcat_tools/importers/matched.py
@@ -1,4 +1,7 @@
+from typing import Any, Dict, List, Optional
+
import fatcat_openapi_client
+from fatcat_openapi_client import ApiClient, FileEntity
from fatcat_tools.normal import clean_doi
@@ -29,7 +32,7 @@ class MatchedImporter(EntityImporter):
- core_id, wikidata_id, pmcid, pmid: not as lists
"""
- def __init__(self, api, **kwargs):
+ def __init__(self, api: ApiClient, **kwargs) -> None:
eg_desc = (
kwargs.pop("editgroup_description", None)
@@ -41,10 +44,10 @@ class MatchedImporter(EntityImporter):
self.default_link_rel = kwargs.get("default_link_rel", "web")
self.default_mimetype = kwargs.get("default_mimetype", None)
- def want(self, raw_record):
+ def want(self, raw_record: Any) -> bool:
return True
- def parse_record(self, obj):
+ def parse_record(self, obj: Dict[str, Any]) -> Optional[FileEntity]:
dois = [d.lower() for d in obj.get("dois", [])]
# lookup dois
@@ -129,7 +132,7 @@ class MatchedImporter(EntityImporter):
if urls[0].url.endswith(".pdf"):
mimetype = "application/pdf"
- fe = fatcat_openapi_client.FileEntity(
+ fe = FileEntity(
md5=obj.get("md5"),
sha1=obj["sha1"],
sha256=obj.get("sha256"),
@@ -140,7 +143,7 @@ class MatchedImporter(EntityImporter):
)
return fe
- def try_update(self, fe):
+ def try_update(self, fe: FileEntity) -> bool:
# lookup sha1, or create new entity
existing = None
try:
@@ -207,7 +210,7 @@ class MatchedImporter(EntityImporter):
self.counts["update"] += 1
return False
- def insert_batch(self, batch):
+ def insert_batch(self, batch: List[FileEntity]) -> None:
self.api.create_file_auto_batch(
fatcat_openapi_client.FileAutoBatch(
editgroup=fatcat_openapi_client.Editgroup(