diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2021-11-02 19:51:48 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2021-11-02 19:51:51 -0700 |
commit | 4c77bdb8d92523935454f1c406c954913f923c01 (patch) | |
tree | 2b2a1221cc78683afb9f18a87ccfd10ef0afbc64 /python/fatcat_web/search.py | |
parent | 3da07382d682a0c474ddc79f748a50ad2cc758cd (diff) | |
download | fatcat-4c77bdb8d92523935454f1c406c954913f923c01.tar.gz fatcat-4c77bdb8d92523935454f1c406c954913f923c01.zip |
lint: resolve existing mypy type errors
Adds annotations and re-workes dataflow to satisfy existing mypy issues,
without adding any additional type annotations to, eg, function
signatures.
There will probably be many more type errors when annotations are all
added.
Diffstat (limited to 'python/fatcat_web/search.py')
-rw-r--r-- | python/fatcat_web/search.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/python/fatcat_web/search.py b/python/fatcat_web/search.py index 5fc3f614..5e758fd0 100644 --- a/python/fatcat_web/search.py +++ b/python/fatcat_web/search.py @@ -6,7 +6,7 @@ the formal API) import datetime import sys from dataclasses import dataclass -from typing import Any, List, Optional +from typing import Any, Dict, List, Optional import elasticsearch import elasticsearch_dsl.response @@ -135,18 +135,22 @@ def wrap_es_execution(search: Search) -> Any: # this is a "user" error print("elasticsearch 400: " + str(e.info), file=sys.stderr) description = None + assert isinstance(e.info, dict) if e.info.get("error", {}).get("root_cause", {}): description = str(e.info["error"]["root_cause"][0].get("reason")) - raise FatcatSearchError(e.status_code, str(e.error), description) + raise FatcatSearchError(int(e.status_code), str(e.error), description) except elasticsearch.exceptions.ConnectionError as e: - raise FatcatSearchError(e.status_code, "ConnectionError: search engine not available") + raise FatcatSearchError( + int(e.status_code), "ConnectionError: search engine not available" + ) except elasticsearch.exceptions.TransportError as e: # all other errors print("elasticsearch non-200 status code: {}".format(e.info), file=sys.stderr) description = None + assert isinstance(e.info, dict) if e.info and e.info.get("error", {}).get("root_cause", {}): description = str(e.info["error"]["root_cause"][0].get("reason")) - raise FatcatSearchError(e.status_code, str(e.error), description) + raise FatcatSearchError(int(e.status_code), str(e.error), description) return resp @@ -285,7 +289,7 @@ def do_release_search(query: ReleaseQuery, deep_page_limit: int = 2000) -> Searc ) -def get_elastic_container_random_releases(ident: str, limit=5) -> dict: +def get_elastic_container_random_releases(ident: str, limit=5) -> List[Dict[str, Any]]: """ Returns a list of releases from the container. """ @@ -750,7 +754,7 @@ def get_elastic_preservation_by_date(query) -> List[dict]: resp = wrap_es_execution(search) buckets = resp.aggregations.date_preservation.buckets - date_dicts = dict() + date_dicts: Dict[str, Dict[str, Any]] = dict() this_date = start_date while this_date <= end_date: date_dicts[str(this_date)] = dict( |