diff --git a/lambda/app/Makefile b/lambda/app/Makefile index 0a445315..5bd4e81f 100644 --- a/lambda/app/Makefile +++ b/lambda/app/Makefile @@ -24,7 +24,7 @@ lint-check: .PHONY: type-check type-check: - pipenv run mypy . + pipenv run mypy . --disallow-untyped-calls .PHONY: test test: export AWS_DEFAULT_REGION := us-east-1 diff --git a/lambda/app/app.py b/lambda/app/app.py index 210b4d0e..8d6b5aa4 100644 --- a/lambda/app/app.py +++ b/lambda/app/app.py @@ -5,7 +5,7 @@ import boto3 # type: ignore from slack_bolt.adapter.aws_lambda import SlackRequestHandler -SlackRequestHandler.clear_all_log_handlers() +SlackRequestHandler.clear_all_log_handlers() # type: ignore secretsmanager_client = boto3.client("secretsmanager") diff --git a/lambda/app/bee_slack_app/repository/book_repository.py b/lambda/app/bee_slack_app/repository/book_repository.py index ba4649b0..0c4417cc 100644 --- a/lambda/app/bee_slack_app/repository/book_repository.py +++ b/lambda/app/bee_slack_app/repository/book_repository.py @@ -1,4 +1,4 @@ -from typing import Optional, TypedDict +from typing import Optional, Tuple, TypedDict import boto3 # type: ignore @@ -27,7 +27,7 @@ class GetConditions(TypedDict): score_for_me: Optional[str] score_for_others: Optional[str] - def __init__(self): + def __init__(self) -> None: self.table = database.get_table() def put(self, *, book: Book) -> None: @@ -95,8 +95,9 @@ def fetch_all( items: レビュー投稿日時が新しい順にソート済みの、本のリスト last_key: 読み込んだ最後のキー """ + QueryResult = Tuple[list[Book], Optional[BookItemKey]] - def query(exclusive_start_key=None, max_item_count=None): + def query(exclusive_start_key=None, max_item_count=None) -> QueryResult: option = {} if exclusive_start_key: option["ExclusiveStartKey"] = exclusive_start_key diff --git a/lambda/app/bee_slack_app/repository/database.py b/lambda/app/bee_slack_app/repository/database.py index 5e8b7c88..631f85b8 100644 --- a/lambda/app/bee_slack_app/repository/database.py +++ b/lambda/app/bee_slack_app/repository/database.py @@ -1,4 +1,5 @@ import os +from typing import Any import boto3 # type: ignore @@ -14,8 +15,10 @@ GSI_2_SK = "GSI_2_SK" GSI_3_SK = "GSI_3_SK" +DynamoDBResource = Any -def get_database_client(): + +def get_database_client() -> DynamoDBResource: """ 環境変数にDYNAMODB_ENDPOINTが設定されていればそこに接続する(ローカル環境) 設定されていなければデフォルトのDynamoDBに接続する(AWSの環境) @@ -26,7 +29,10 @@ def get_database_client(): return dynamodb -def get_table(): +DynamoDBTable = Any + + +def get_table() -> DynamoDBTable: return get_database_client().Table(os.environ["DYNAMODB_TABLE"]) diff --git a/lambda/app/bee_slack_app/repository/google_books_repository.py b/lambda/app/bee_slack_app/repository/google_books_repository.py index d46afff0..88ecf302 100644 --- a/lambda/app/bee_slack_app/repository/google_books_repository.py +++ b/lambda/app/bee_slack_app/repository/google_books_repository.py @@ -5,7 +5,7 @@ class GoogleBooksRepository: - def __init__(self): + def __init__(self) -> None: # Google API self.base_url_google = "https://www.googleapis.com/books/v1/volumes" @@ -111,7 +111,7 @@ def search_book_by_isbn(self, isbn: str) -> Optional[dict[str, Any]]: return dict_info @staticmethod - def _get_image_url(_item): + def _get_image_url(_item: dict[str, Any]) -> Optional[str]: if ( _item["volumeInfo"].get("imageLinks") is not None and _item["volumeInfo"].get("imageLinks").get("thumbnail") is not None diff --git a/lambda/app/bee_slack_app/repository/review_repository.py b/lambda/app/bee_slack_app/repository/review_repository.py index 0d6e0d76..ad2ebe8f 100644 --- a/lambda/app/bee_slack_app/repository/review_repository.py +++ b/lambda/app/bee_slack_app/repository/review_repository.py @@ -1,4 +1,4 @@ -from typing import Optional, TypedDict +from typing import Any, Optional, Tuple, TypedDict import boto3 # type: ignore from boto3.dynamodb.conditions import Key # type: ignore @@ -27,7 +27,7 @@ class GetConditions(TypedDict): score_for_me: Optional[str] score_for_others: Optional[str] - def __init__(self): + def __init__(self) -> None: self.table = database.get_table() def fetch(self, *, user_id: str, isbn: str) -> Optional[Review]: @@ -50,7 +50,9 @@ def fetch_all(self) -> list[Review]: Returns: 本のレビューのリスト """ - def query(exclusive_start_key=None): + QueryResult = Tuple[list[Review], Optional[ReviewItemKey]] + + def query(exclusive_start_key=None) -> QueryResult: option = {} if exclusive_start_key: option["ExclusiveStartKey"] = exclusive_start_key @@ -120,7 +122,9 @@ def fetch_limited_by_user_id( GetResponse: レビューのリストと、読み込んだ最後のキー """ - def query(exclusive_start_key=None, max_item_count=None): + QueryResult = Tuple[list[Review], Optional[ReviewItemKey]] + + def query(exclusive_start_key=None, max_item_count=None) -> QueryResult: option = {} if exclusive_start_key: option["ExclusiveStartKey"] = exclusive_start_key @@ -145,7 +149,7 @@ def query(exclusive_start_key=None, max_item_count=None): return {"items": items, "last_key": last_key} - def put(self, review): + def put(self, review: Review) -> dict[str, Any]: partition_key = _encode_partition_key( user_id=review["user_id"], isbn=review["isbn"] ) diff --git a/lambda/app/bee_slack_app/repository/suggested_book_repository.py b/lambda/app/bee_slack_app/repository/suggested_book_repository.py index 0a07b088..cdeff0b5 100644 --- a/lambda/app/bee_slack_app/repository/suggested_book_repository.py +++ b/lambda/app/bee_slack_app/repository/suggested_book_repository.py @@ -13,7 +13,7 @@ def _encode_partition_key(*, user_id: str, isbn: str, ml_model: str) -> str: class SuggestedBookRepository: - def __init__(self): + def __init__(self) -> None: self.table = database.get_table() def fetch( diff --git a/lambda/app/bee_slack_app/repository/user_action_repository.py b/lambda/app/bee_slack_app/repository/user_action_repository.py index 246b91d8..e3c67bf8 100644 --- a/lambda/app/bee_slack_app/repository/user_action_repository.py +++ b/lambda/app/bee_slack_app/repository/user_action_repository.py @@ -9,7 +9,7 @@ def _encode_partition_key(*, user_id: str, created_at: str) -> str: class UserActionRepository: # pylint: disable=too-few-public-methods - def __init__(self): + def __init__(self) -> None: self.table = database.get_table() def put(self, user_action: UserAction) -> None: diff --git a/lambda/app/bee_slack_app/repository/user_repository.py b/lambda/app/bee_slack_app/repository/user_repository.py index cc325130..32a42e0b 100644 --- a/lambda/app/bee_slack_app/repository/user_repository.py +++ b/lambda/app/bee_slack_app/repository/user_repository.py @@ -15,7 +15,7 @@ def _encode_partition_key(*, user_id: str) -> str: class UserRepository: - def __init__(self): + def __init__(self) -> None: self.table = database.get_table() def fetch(self, user_id: str) -> Optional[User]: diff --git a/lambda/app/bee_slack_app/utils/timer.py b/lambda/app/bee_slack_app/utils/timer.py index 05c65c62..f9a07300 100644 --- a/lambda/app/bee_slack_app/utils/timer.py +++ b/lambda/app/bee_slack_app/utils/timer.py @@ -1,3 +1,4 @@ +# type: ignore import inspect import os from datetime import datetime diff --git a/lambda/app/bee_slack_app/view/book_search.py b/lambda/app/bee_slack_app/view/book_search.py index 38ad4567..a3fb9fdd 100644 --- a/lambda/app/bee_slack_app/view/book_search.py +++ b/lambda/app/bee_slack_app/view/book_search.py @@ -1,3 +1,5 @@ +from typing import Any + from bee_slack_app.model import SearchedBook from bee_slack_app.view.common import DUMMY_IMAGE_URL, google_graphic @@ -128,7 +130,7 @@ def book_search_result_selected_modal( } -def _selected_book(item): +def _selected_book(item) -> dict[str, Any]: """ ボタンが選択された本のblockを生成する """ @@ -160,7 +162,7 @@ def _selected_book(item): } -def _unselected_book(item): +def _unselected_book(item) -> dict[str, Any]: """ ボタンが選択されていない本のblockを生成する """ diff --git a/lambda/app/bee_slack_app/view/common.py b/lambda/app/bee_slack_app/view/common.py index dc39488b..71692f53 100644 --- a/lambda/app/bee_slack_app/view/common.py +++ b/lambda/app/bee_slack_app/view/common.py @@ -1,5 +1,5 @@ import os -from typing import Optional +from typing import Any, Optional def simple_modal( @@ -54,7 +54,7 @@ def book_section( } -def google_graphic(): +def google_graphic() -> dict[str, Any]: """ 「Powered by Google」 """ diff --git a/lambda/app/bee_slack_app/view/read_review.py b/lambda/app/bee_slack_app/view/read_review.py index 8e01be8e..0a821ec6 100644 --- a/lambda/app/bee_slack_app/view/read_review.py +++ b/lambda/app/bee_slack_app/view/read_review.py @@ -1,4 +1,4 @@ -from typing import TypedDict +from typing import Any, TypedDict from bee_slack_app.model import Review, ReviewPagination from bee_slack_app.utils import datetime @@ -155,7 +155,7 @@ def review_of_user_modal( return view -def review_detail_modal(review_contents: Review): +def review_detail_modal(review_contents: Review) -> dict[str, Any]: """ レビュー詳細モーダル diff --git a/lambda/app/bee_slack_app/view_controller/book_search.py b/lambda/app/bee_slack_app/view_controller/book_search.py index 4cb07f59..9d647a7c 100644 --- a/lambda/app/bee_slack_app/view_controller/book_search.py +++ b/lambda/app/bee_slack_app/view_controller/book_search.py @@ -1,5 +1,7 @@ import json +from slack_bolt import App + from bee_slack_app.service import book_search_service, user_action_service from bee_slack_app.view import ( book_search_result_modal, @@ -10,7 +12,7 @@ # TODO: disable=too-many-statementsを取り消す -def book_search_controller(app): # pylint: disable=too-many-statements +def book_search_controller(app: App) -> None: # pylint: disable=too-many-statements @app.view("book_search_modal") def open_book_search_result_modal(ack, body): """ diff --git a/lambda/app/bee_slack_app/view_controller/hello.py b/lambda/app/bee_slack_app/view_controller/hello.py index 09167238..af7e5f71 100644 --- a/lambda/app/bee_slack_app/view_controller/hello.py +++ b/lambda/app/bee_slack_app/view_controller/hello.py @@ -1,10 +1,12 @@ import os +from slack_bolt import App + from bee_slack_app.service import review_service -from bee_slack_app.utils.timer import StopWatch, location +from bee_slack_app.utils.timer import StopWatch, location # type: ignore -def hello_controller(app): +def hello_controller(app: App) -> None: @app.message("hello") def message_hello(message, say): # say() sends a message to the channel where the event was triggered diff --git a/lambda/app/bee_slack_app/view_controller/home.py b/lambda/app/bee_slack_app/view_controller/home.py index 42f2bf1c..afcad9c1 100644 --- a/lambda/app/bee_slack_app/view_controller/home.py +++ b/lambda/app/bee_slack_app/view_controller/home.py @@ -2,6 +2,8 @@ from logging import getLogger from typing import Any, TypedDict +from slack_bolt import App + from bee_slack_app.model import SuggestedBook from bee_slack_app.service import ( book_service, @@ -16,7 +18,7 @@ BOOK_NUMBER_PER_PAGE = 20 -def home_controller(app): # pylint: disable=too-many-statements +def home_controller(app: App) -> None: # pylint: disable=too-many-statements @app.event("app_home_opened") def update_home_view(ack, event, client): ack() diff --git a/lambda/app/bee_slack_app/view_controller/review.py b/lambda/app/bee_slack_app/view_controller/review.py index a15784a7..0ff776bb 100644 --- a/lambda/app/bee_slack_app/view_controller/review.py +++ b/lambda/app/bee_slack_app/view_controller/review.py @@ -2,6 +2,8 @@ import os from typing import Any, TypedDict +from slack_bolt import App + from bee_slack_app.model import Review, ReviewPagination, User from bee_slack_app.service import ( book_search_service, @@ -24,7 +26,7 @@ BOOK_NUMBER_PER_PAGE = 19 -def review_controller(app): # pylint: disable=too-many-statements +def review_controller(app: App) -> None: # pylint: disable=too-many-statements @app.action("read_review_of_book_action") def read_review_of_book_action(ack, body, client, action): """ diff --git a/lambda/app/bee_slack_app/view_controller/user.py b/lambda/app/bee_slack_app/view_controller/user.py index 57885ebd..413c26eb 100644 --- a/lambda/app/bee_slack_app/view_controller/user.py +++ b/lambda/app/bee_slack_app/view_controller/user.py @@ -1,12 +1,14 @@ import json from typing import Optional, TypedDict +from slack_bolt import App + from bee_slack_app.model import User from bee_slack_app.service import user_action_service, user_service from bee_slack_app.view import user_profile_modal -def user_controller(app): +def user_controller(app: App) -> None: @app.action("user_info_action") def open_user_info(ack, body, client): ack() diff --git a/lambda/app/bee_slack_app/view_controller/user_list.py b/lambda/app/bee_slack_app/view_controller/user_list.py index 31f132c4..8398355c 100644 --- a/lambda/app/bee_slack_app/view_controller/user_list.py +++ b/lambda/app/bee_slack_app/view_controller/user_list.py @@ -1,8 +1,10 @@ +from slack_bolt import App + from bee_slack_app.service.user import get_users_posted_review from bee_slack_app.view import posted_review_user_list_modal -def user_list_controller(app): +def user_list_controller(app: App) -> None: @app.action("list_user_posted_review_action") def list_user_posted_review_action(ack, body, client): """