aboutsummaryrefslogtreecommitdiffstats
path: root/python/fatcat_tools/importers/shadow.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/shadow.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/shadow.py')
-rw-r--r--python/fatcat_tools/importers/shadow.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/python/fatcat_tools/importers/shadow.py b/python/fatcat_tools/importers/shadow.py
index 78eeec7a..520258cb 100644
--- a/python/fatcat_tools/importers/shadow.py
+++ b/python/fatcat_tools/importers/shadow.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, clean_isbn13, clean_pmid
@@ -27,7 +30,7 @@ class ShadowLibraryImporter(EntityImporter):
- datetime
"""
- def __init__(self, api, **kwargs):
+ def __init__(self, api: ApiClient, **kwargs) -> None:
eg_desc = (
kwargs.pop("editgroup_description", None)
@@ -38,7 +41,7 @@ class ShadowLibraryImporter(EntityImporter):
super().__init__(api, editgroup_description=eg_desc, editgroup_extra=eg_extra, **kwargs)
self.default_link_rel = kwargs.get("default_link_rel", "web")
- def want(self, raw_record):
+ def want(self, raw_record: Any) -> bool:
"""
Only want to import records with complete file-level metadata
"""
@@ -51,7 +54,7 @@ class ShadowLibraryImporter(EntityImporter):
return False
return True
- def parse_record(self, obj):
+ def parse_record(self, obj: Dict[str, Any]) -> Optional[FileEntity]:
"""
We do the release lookup in this method. Try DOI, then PMID, last ISBN13.
"""
@@ -104,7 +107,7 @@ class ShadowLibraryImporter(EntityImporter):
urls.append(("webarchive", wayback))
urls = [fatcat_openapi_client.FileUrl(rel=rel, url=url) for (rel, url) in urls]
- fe = fatcat_openapi_client.FileEntity(
+ fe = FileEntity(
md5=obj["file_meta"]["md5hex"],
sha1=obj["file_meta"]["sha1hex"],
sha256=obj["file_meta"]["sha256hex"],
@@ -116,7 +119,7 @@ class ShadowLibraryImporter(EntityImporter):
)
return fe
- def try_update(self, fe):
+ def try_update(self, fe: FileEntity) -> Optional[bool]:
# lookup sha1, or create new entity
existing = None
try:
@@ -189,7 +192,7 @@ class ShadowLibraryImporter(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(