Skip to content

Commit f17ea39

Browse files
authored
Start migrating source code to strict typing (#283)
In this commit, we start the process of migrating the project to being strictly typed with mypy. To do this, we use mypy config to enable all strict type rules that apply to the module level (some strict rules can't be applied at the module level). We also specify a list of modules to apply those rules against. The goal will be to gradually add more modules to the list until we've added all of the modules, at which point we will check the entire source directory with `strict` enabled.
1 parent 0c124d8 commit f17ea39

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

jbi/app.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
import logging
55
import time
66
from pathlib import Path
7+
from typing import Awaitable, Callable
78

89
import sentry_sdk
9-
from fastapi import FastAPI, Request
10+
from fastapi import FastAPI, Request, Response
1011
from fastapi.staticfiles import StaticFiles
1112
from sentry_sdk.integrations.fastapi import FastApiIntegration
1213
from sentry_sdk.integrations.starlette import StarletteIntegration
@@ -41,7 +42,9 @@
4142

4243

4344
@app.middleware("http")
44-
async def request_summary(request: Request, call_next):
45+
async def request_summary(
46+
request: Request, call_next: Callable[[Request], Awaitable[Response]]
47+
) -> Response:
4548
"""Middleware to log request info"""
4649
summary_logger = logging.getLogger("request.summary")
4750
request_time = time.time()

pyproject.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,24 @@ warn_return_any = true
8181
module = ["ruamel", "bugzilla", "atlassian", "statsd.defaults.env"]
8282
ignore_missing_imports = true
8383

84+
[[tool.mypy.overrides]]
85+
module = [
86+
"jbi.app"
87+
]
88+
disallow_any_generics = true
89+
disallow_subclassing_any = true
90+
disallow_untyped_calls = true
91+
disallow_untyped_defs = true
92+
disallow_incomplete_defs = true
93+
check_untyped_defs = true
94+
disallow_untyped_decorators = true
95+
no_implicit_optional = true
96+
warn_unused_ignores = true
97+
warn_return_any = true
98+
no_implicit_reexport = true
99+
strict_equality = true
100+
strict_concatenate = true
101+
84102
[tool.coverage]
85103
# https://github.com/nedbat/coveragepy
86104
[tool.coverage.run]

0 commit comments

Comments
 (0)