Skip to content

Add mypy #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/test_for_python_test_example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ jobs:
- name: Install Library
run: |
python3 -m pip install --upgrade pip
pip install requests flask
pip install requests flask mypy
- name: Run mypy
run: |
mypy python_test_example --config-file python_test_example/mypy.ini
- name: Run unittest
run: |
cd python_test_example
Expand Down
2 changes: 1 addition & 1 deletion python_test_example/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.7-slim

RUN pip install --no-cache-dir --upgrade pip setuptools wheel \
&& pip install --no-cache-dir requests flask
&& pip install --no-cache-dir requests flask mypy
4 changes: 4 additions & 0 deletions python_test_example/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ dbuild:
drun:
docker run --rm -it -v $(curdir):/opt -w /opt $(image):$(tag) bash

.PHONY: drmi
drmi:
docker rmi -f $(image):$(tag)

.PHONY: all_test
all_test:
python3 -m unittest discover --verbose --pattern "*_test.py"
5 changes: 3 additions & 2 deletions python_test_example/flask_app/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json

from flask import Flask, jsonify, make_response
from flask.wrappers import Response

from .service import Service

Expand All @@ -10,12 +11,12 @@
service = Service()

@app.route('/', methods=['GET'])
def index():
def index() -> Response:
message = {'message': 'OK'}
return make_response(jsonify(message), 200)

@app.route('/predict', methods=['POST'])
def predict():
def predict() -> Response:
print('Call predict in app')
target = 'A'
if not service.check_model():
Expand Down
2 changes: 1 addition & 1 deletion python_test_example/flask_app/model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def load_model():
def load_model() -> str:
print('Call load_model in model')
return 'model'
2 changes: 1 addition & 1 deletion python_test_example/flask_app/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
print('In service')

class Service:
def __init__(self):
def __init__(self) -> None:
print('Init Service')
self.model = load_model()
print(f'self.model: {self.model}')
Expand Down
18 changes: 18 additions & 0 deletions python_test_example/mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[mypy]
python_version = 3.7
disallow_untyped_defs = True
ignore_missing_imports = True
warn_redundant_casts = True
no_implicit_optional = True

[mypy-flask_app.app_test.*]
disallow_untyped_defs = False

[mypy-i76_testcase_subclass.utils_test.*]
disallow_untyped_defs = False

[mypy-i77_setup_and_teardown.*]
disallow_untyped_defs = False

[mypy-mock.my_class_test.*]
disallow_untyped_defs = False