Skip to content

Commit

Permalink
Add support for mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
avnes committed Jun 16, 2021
1 parent f73d84c commit eb63c7b
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 10 deletions.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: run install dev lint test coverage check docker-test
.PHONY: run install dev mypy lint test coverage check docker-test

PACKAGE_DIR:=python_template_project

Expand All @@ -11,8 +11,12 @@ install:
dev:
poetry install && poetry run pre-commit install

mypy:
poetry run mypy $(PACKAGE_DIR) tests main.py

lint:
poetry run flake8 $(PACKAGE_DIR) tests
$(MAKE) mypy
poetry run flake8 $(PACKAGE_DIR) tests main.py

test:
poetry run pytest
Expand Down
68 changes: 67 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ authors = ["Audun Nes <REDACTED>"]
[tool.poetry.dependencies]
python = "^3.9"
requests = "^2.25.1"
types-requests = "^0.1.11"

[tool.poetry.dev-dependencies]
pytest = "^5.2"
Expand All @@ -16,6 +17,7 @@ pre-commit = "^2.13.0"
pytest-cov = "^2.12.1"
bandit = "^1.7.0"
isort = "^5.8.0"
mypy = "^0.902"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
21 changes: 14 additions & 7 deletions python_template_project/demo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import requests
from typing import Dict, Optional

from requests import Response
from requests import get as requests_get

API_URL: str = "http://api.icndb.com/jokes/random"

Expand All @@ -14,16 +16,21 @@ def __init__(self) -> None:
pass

@staticmethod
def _get_joke() -> dict:
def _get_joke() -> Optional[Dict]:
"""
Get a random joke from the internet Chuck Norris database.
return: dict
return: Optional[Dict]
"""
response: Response = requests.get(API_URL)
return response.json()
response: Response = requests_get(API_URL)
joke: Optional[Dict] = response.json()
return joke

def print_joke(self) -> None:
"""Print the joke to standard out."""
joke: dict = self._get_joke()
print(joke.get("value").get("joke"))
joke: Optional[Dict] = self._get_joke()
if joke is not None:
joke_value: Optional[Dict] = joke.get("value")
if joke_value is not None:
joke_msg: Optional[str] = joke_value.get("joke")
print(joke_msg)

0 comments on commit eb63c7b

Please sign in to comment.