summaryrefslogtreecommitdiffstats
path: root/fatcat_scholar
diff options
context:
space:
mode:
Diffstat (limited to 'fatcat_scholar')
-rw-r--r--fatcat_scholar/api_entities.py12
-rw-r--r--fatcat_scholar/search.py2
-rw-r--r--fatcat_scholar/transform.py6
-rw-r--r--fatcat_scholar/web.py14
4 files changed, 20 insertions, 14 deletions
diff --git a/fatcat_scholar/api_entities.py b/fatcat_scholar/api_entities.py
index df24eda..c4a4ace 100644
--- a/fatcat_scholar/api_entities.py
+++ b/fatcat_scholar/api_entities.py
@@ -1,11 +1,13 @@
import json
import collections
+from typing import Any, Optional
+
from fatcat_openapi_client import ApiClient
_global_serde_api_client = ApiClient()
-def entity_to_dict(entity, api_client=None):
+def entity_to_dict(entity: Any, api_client: Optional[ApiClient] = None) -> dict:
"""
Hack to take advantage of the code-generated serialization code.
@@ -20,7 +22,9 @@ def entity_to_dict(entity, api_client=None):
return api_client.sanitize_for_serialization(entity)
-def entity_from_json(json_str, entity_type, api_client=None):
+def entity_from_json(
+ json_str: str, entity_type: Any, api_client: Optional[ApiClient] = None
+) -> Any:
"""
Hack to take advantage of the code-generated deserialization code
@@ -33,6 +37,8 @@ def entity_from_json(json_str, entity_type, api_client=None):
return api_client.deserialize(thing, entity_type)
-def entity_from_dict(obj, entity_type, api_client=None):
+def entity_from_dict(
+ obj: dict, entity_type: Any, api_client: Optional[ApiClient] = None
+) -> Any:
json_str = json.dumps(obj)
return entity_from_json(json_str, entity_type, api_client=api_client)
diff --git a/fatcat_scholar/search.py b/fatcat_scholar/search.py
index 3d9ca9b..6402e2b 100644
--- a/fatcat_scholar/search.py
+++ b/fatcat_scholar/search.py
@@ -209,7 +209,7 @@ def do_fulltext_search(
# Avoid deep paging problem.
offset = deep_page_limit
- search = search[offset:(offset+limit)]
+ search = search[offset : (offset + limit)]
try:
resp = search.execute()
diff --git a/fatcat_scholar/transform.py b/fatcat_scholar/transform.py
index 28c959b..3d47fb4 100644
--- a/fatcat_scholar/transform.py
+++ b/fatcat_scholar/transform.py
@@ -1,6 +1,6 @@
import sys
import argparse
-from typing import List, Dict, Optional, Any
+from typing import List, Dict, Optional, Any, Sequence
from fatcat_openapi_client import ReleaseEntity, FileEntity
@@ -329,7 +329,7 @@ def transform_heavy(heavy: IntermediateBundle) -> Optional[ScholarDoc]:
)
-def run_transform(infile):
+def run_transform(infile: Sequence) -> None:
for line in infile:
obj = json.loads(line)
@@ -350,7 +350,7 @@ def run_transform(infile):
print(es_doc.json())
-def main():
+def main() -> None:
"""
Run this command like:
diff --git a/fatcat_scholar/web.py b/fatcat_scholar/web.py
index 3f6982d..4e912d4 100644
--- a/fatcat_scholar/web.py
+++ b/fatcat_scholar/web.py
@@ -9,7 +9,7 @@ import babel.support
from fastapi import FastAPI, APIRouter, Request, Depends
from fastapi.staticfiles import StaticFiles
from dynaconf import settings
-from typing import Optional
+from typing import Optional, List, Any
from fatcat_scholar.hacks import Jinja2Templates
from fatcat_scholar.search import do_fulltext_search, FulltextQuery, FulltextHits
@@ -58,26 +58,26 @@ api = APIRouter()
@api.get("/", operation_id="get_home")
-async def home():
+async def home() -> Any:
return {"endpoints": {"/": "this", "/search": "fulltext search"}}
@api.get("/search", operation_id="get_search")
-async def search(query: FulltextQuery = Depends(FulltextQuery)):
+async def search(query: FulltextQuery = Depends(FulltextQuery)) -> Any:
return {"message": "search results would go here, I guess"}
web = APIRouter()
-def locale_gettext(translations):
+def locale_gettext(translations: List[Any]) -> Any:
def gt(s):
return translations.ugettext(s)
return gt
-def locale_ngettext(translations):
+def locale_ngettext(translations: List[Any]) -> Any:
def ngt(s, n):
return translations.ungettext(s)
@@ -144,7 +144,7 @@ async def web_about(request: Request, lang: LangPrefix = Depends(LangPrefix)):
@web.get("/help", include_in_schema=False)
-async def web_help(request: Request, lang: LangPrefix = Depends(LangPrefix)):
+async def web_help(request: Request, lang: LangPrefix = Depends(LangPrefix)) -> Any:
return i18n_templates[lang.code].TemplateResponse(
"help.html",
{"request": request, "locale": lang.code, "lang_prefix": lang.prefix},
@@ -157,7 +157,7 @@ async def web_search(
query: FulltextQuery = Depends(FulltextQuery),
lang: LangPrefix = Depends(LangPrefix),
content: ContentNegotiation = Depends(ContentNegotiation),
-):
+) -> Any:
if content.mimetype == "application/json":
return await search(query)