From ecbaa7ff48d046e77547a69dd2be8ef0c7b9bf04 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 17 Nov 2021 17:31:59 -0800 Subject: WIP: start fixing types and lints from openapi annotations --- python/fatcat_tools/cleanups/common.py | 6 +++--- python/fatcat_tools/transforms/elasticsearch.py | 5 +++-- python/fatcat_tools/transforms/entities.py | 2 +- python/fatcat_tools/workers/elasticsearch.py | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/python/fatcat_tools/cleanups/common.py b/python/fatcat_tools/cleanups/common.py index 1b467b59..aa26acaf 100644 --- a/python/fatcat_tools/cleanups/common.py +++ b/python/fatcat_tools/cleanups/common.py @@ -54,7 +54,7 @@ class EntityCleaner: def reset(self) -> None: self.counts = Counter({"lines": 0, "cleaned": 0, "updated": 0}) self._edit_count = 0 - self._editgroup_id = None + self._editgroup_id: Optional[str] = None self._entity_queue: List[Any] = [] self._idents_inflight: List[str] = [] @@ -72,7 +72,7 @@ class EntityCleaner: self.counts["skip-null"] += 1 return - entity = entity_from_dict(record, self.entity_type, api_client=self.ac) + entity = entity_from_dict(record, self.entity_type, api_client=self.ac.api_client) if entity.state != "active": self.counts["skip-inactive"] += 1 @@ -86,7 +86,7 @@ class EntityCleaner: self.counts["cleaned"] += 1 if self.dry_run_mode: - entity_dict = entity_to_dict(entity, api_client=self.ac) + entity_dict = entity_to_dict(entity, api_client=self.ac.api_client) print(json.dumps(entity_dict)) return diff --git a/python/fatcat_tools/transforms/elasticsearch.py b/python/fatcat_tools/transforms/elasticsearch.py index c16053ec..11e133b7 100644 --- a/python/fatcat_tools/transforms/elasticsearch.py +++ b/python/fatcat_tools/transforms/elasticsearch.py @@ -279,7 +279,7 @@ def _rte_container_helper(container: ContainerEntity, release_year: Optional[int Container metadata sub-section of release_to_elasticsearch() """ this_year = datetime.date.today().year - t = dict() + t: Dict[str, Any] = dict() t["publisher"] = container.publisher t["container_name"] = container.name # this is container.ident, not release.container_id, because there may @@ -325,7 +325,8 @@ def _rte_container_helper(container: ContainerEntity, release_year: Optional[int if c_extra.get("sherpa_romeo"): if c_extra["sherpa_romeo"].get("color") == "white": t["is_oa"] = False - if c_extra.get("default_license") and c_extra.get("default_license").startswith("CC-"): + c_default_license = c_extra.get("default_license") + if c_default_license and c_default_license.startswith("CC-"): t["is_oa"] = True if c_extra.get("doaj"): if c_extra["doaj"].get("as_of"): diff --git a/python/fatcat_tools/transforms/entities.py b/python/fatcat_tools/transforms/entities.py index e5da633f..4066297b 100644 --- a/python/fatcat_tools/transforms/entities.py +++ b/python/fatcat_tools/transforms/entities.py @@ -58,7 +58,7 @@ def entity_to_toml( def entity_from_toml( - toml_str: str, entity_type: Any, api_client: Optional[List[str]] = None + toml_str: str, entity_type: Any, api_client: Optional[ApiClient] = None ) -> Any: obj = toml.loads(toml_str) return entity_from_dict(obj, entity_type, api_client=api_client) diff --git a/python/fatcat_tools/workers/elasticsearch.py b/python/fatcat_tools/workers/elasticsearch.py index 7c959e93..3129d93f 100644 --- a/python/fatcat_tools/workers/elasticsearch.py +++ b/python/fatcat_tools/workers/elasticsearch.py @@ -1,6 +1,6 @@ import json import sys -from typing import Any, Callable, List, Optional +from typing import Any, Callable, List, Optional, Union import elasticsearch import requests -- cgit v1.2.3