Skip to content
This repository has been archived by the owner on May 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #430 from esminc/mypy-disallow-untyped-calls
Browse files Browse the repository at this point in the history
mypyの--disallow-untyped-callsを有効化
  • Loading branch information
Hiroki SAKABE authored Jan 24, 2023
2 parents 2033873 + c826104 commit d06aef3
Show file tree
Hide file tree
Showing 19 changed files with 56 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lambda/app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lambda/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 4 additions & 3 deletions lambda/app/bee_slack_app/repository/book_repository.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional, TypedDict
from typing import Optional, Tuple, TypedDict

import boto3 # type: ignore

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions lambda/app/bee_slack_app/repository/database.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from typing import Any

import boto3 # type: ignore

Expand All @@ -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の環境)
Expand All @@ -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"])


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions lambda/app/bee_slack_app/repository/review_repository.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion lambda/app/bee_slack_app/repository/user_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
1 change: 1 addition & 0 deletions lambda/app/bee_slack_app/utils/timer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
import inspect
import os
from datetime import datetime
Expand Down
6 changes: 4 additions & 2 deletions lambda/app/bee_slack_app/view/book_search.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -128,7 +130,7 @@ def book_search_result_selected_modal(
}


def _selected_book(item):
def _selected_book(item) -> dict[str, Any]:
"""
ボタンが選択された本のblockを生成する
"""
Expand Down Expand Up @@ -160,7 +162,7 @@ def _selected_book(item):
}


def _unselected_book(item):
def _unselected_book(item) -> dict[str, Any]:
"""
ボタンが選択されていない本のblockを生成する
"""
Expand Down
4 changes: 2 additions & 2 deletions lambda/app/bee_slack_app/view/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from typing import Optional
from typing import Any, Optional


def simple_modal(
Expand Down Expand Up @@ -54,7 +54,7 @@ def book_section(
}


def google_graphic():
def google_graphic() -> dict[str, Any]:
"""
「Powered by Google」
"""
Expand Down
4 changes: 2 additions & 2 deletions lambda/app/bee_slack_app/view/read_review.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]:
"""
レビュー詳細モーダル
Expand Down
4 changes: 3 additions & 1 deletion lambda/app/bee_slack_app/view_controller/book_search.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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):
"""
Expand Down
6 changes: 4 additions & 2 deletions lambda/app/bee_slack_app/view_controller/hello.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion lambda/app/bee_slack_app/view_controller/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion lambda/app/bee_slack_app/view_controller/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
"""
Expand Down
4 changes: 3 additions & 1 deletion lambda/app/bee_slack_app/view_controller/user.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
4 changes: 3 additions & 1 deletion lambda/app/bee_slack_app/view_controller/user_list.py
Original file line number Diff line number Diff line change
@@ -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):
"""
Expand Down

0 comments on commit d06aef3

Please sign in to comment.