Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #107 from communitiesuk/type_hint_check
Browse files Browse the repository at this point in the history
SMD-815 data-frontend: enable mypy on pre-commit
  • Loading branch information
sc15zs authored May 15, 2024
2 parents 00391be + 3e9cbb1 commit e142248
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ repos:
args: [ --fix ]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
# mypy. If bumping this, bump requirements-dev.txt as well
rev: 'v1.10.0' # Use the sha / tag you want to point at
hooks:
- id: mypy
additional_dependencies: [types-jmespath, types-requests, types-beautifulsoup4, types-flask, types-python-dateutil]
# - repo: https://github.com/Riverside-Healthcare/djLint
# rev: v1.24.0
# hooks:
Expand Down
2 changes: 1 addition & 1 deletion app/main/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from requests import Response


def get_response(hostname: str, endpoint: str, query_params: dict = None) -> Response:
def get_response(hostname: str, endpoint: str, query_params: dict | None = None) -> Response:
"""Send an HTTP GET request to a remote server and return the response.
This function constructs the request URL using the provided hostname, endpoint, and query parameters (if any).
Expand Down
8 changes: 4 additions & 4 deletions config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
case "unit_test":
from config.envs.unit_test import UnitTestConfig as Config
case "development":
from config.envs.development import DevelopmentConfig as Config
from config.envs.development import DevelopmentConfig as Config # type: ignore # TODO: fixme
# case "dev":
# from config.envs.dev import (
# DevConfig as Config,
Expand All @@ -24,11 +24,11 @@
# ProductionConfig as Config,
# )
case _:
from config.envs.default import DefaultConfig as Config
from config.envs.default import DefaultConfig as Config # type: ignore # TODO: fixme

try:
Config.pretty_print()
Config.pretty_print() # type: ignore # TODO: fixme
except AttributeError:
print({"msg": "Config doesn't have pretty_print function."})

__all__ = [Config]
__all__ = ["Config"]
2 changes: 1 addition & 1 deletion config/envs/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DevelopmentConfig(DefaultConfig):
# RSA 256 KEYS
if not hasattr(DefaultConfig, "RSA256_PUBLIC_KEY"):
_test_public_key_path = DefaultConfig.FLASK_ROOT + "/tests/keys/rsa256/public.pem"
with open(_test_public_key_path, mode="rb") as public_key_file:
with open(_test_public_key_path, mode="r") as public_key_file:
RSA256_PUBLIC_KEY = public_key_file.read()
FSD_LOG_LEVEL = logging.DEBUG

Expand Down
2 changes: 1 addition & 1 deletion config/envs/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class UnitTestConfig(DefaultConfig):
# RSA 256 KEYS
if not hasattr(DefaultConfig, "RSA256_PUBLIC_KEY"):
_test_public_key_path = DefaultConfig.FLASK_ROOT + "/tests/keys/rsa256/public.pem"
with open(_test_public_key_path, mode="rb") as public_key_file:
with open(_test_public_key_path, mode="r") as public_key_file:
RSA256_PUBLIC_KEY = public_key_file.read()

AUTO_BUILD_ASSETS = True
File renamed without changes.
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,14 @@ exclude = [
"__pycache__",
]
mccabe.max-complexity = 12

[tool.mypy]
python_version = "3.11"

[[tool.mypy.overrides]]
module = [
"fsd_utils.*",
"notifications_python_client.*",
"flask_assets"
]
ignore_missing_imports = true
1 change: 1 addition & 0 deletions requirements-dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

bandit==1.7.5
debugpy
mypy
pep8-naming==0.13.3
pip-tools==6.13.0
pur==7.1.0
Expand Down
5 changes: 5 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ markupsafe==2.1.2
# wtforms
mccabe==0.7.0
# via flake8
mypy==1.10.0
# via -r requirements-dev.in
mypy-extensions==1.0.0
# via mypy
notifications-python-client==9.0.0
# via -r requirements.txt
packaging==23.1
Expand Down Expand Up @@ -326,6 +330,7 @@ typing-extensions==4.5.0
# via
# -r requirements.txt
# alembic
# mypy
# sqlalchemy
urllib3==1.26.18
# via
Expand Down
2 changes: 1 addition & 1 deletion scripts/extract_download_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def send_notify(
from_date: datetime.datetime,
to_date: datetime.datetime,
file_buffer: io.BytesIO,
api_key: str = os.getenv("NOTIFY_API_KEY"),
api_key: str | None = os.getenv("NOTIFY_API_KEY"),
template_id: str = "196e5553-886c-40bd-ac9a-981a7868301b",
email_address: str = os.getenv("NOTIFY_SEND_EMAIL", "[email protected]"),
):
Expand Down
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import io
from typing import Generator

import pytest
from flask.testing import FlaskClient
Expand All @@ -20,7 +21,7 @@ def access_token(return_app=SupportedApp.POST_AWARD_FRONTEND, auto_redirect=True


@pytest.fixture()
def flask_test_client(mocked_auth) -> FlaskClient:
def flask_test_client(mocked_auth) -> Generator[FlaskClient, None, None]:
"""
Creates the test client we will be using to test the responses
from our app, this is a test fixture.
Expand All @@ -34,7 +35,7 @@ def flask_test_client(mocked_auth) -> FlaskClient:


@pytest.fixture()
def unauthenticated_flask_test_client() -> FlaskClient:
def unauthenticated_flask_test_client() -> Generator[FlaskClient, None, None]:
"""
:return: An unauthenticated flask test client.
"""
Expand Down

0 comments on commit e142248

Please sign in to comment.