Skip to content

Commit ba0b8d1

Browse files
committed
Fix Python lint issues in Flask app
1 parent e9cf6a7 commit ba0b8d1

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

app/main.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
import logging
22
import time
33
from contextlib import contextmanager
4-
from typing import Any, Dict, Generator, Tuple
4+
from typing import Any, Callable, Dict, Generator, Tuple, TypeVar, cast
55

66
from flask import Flask, Response, jsonify, request
7+
from flask.typing import ResponseReturnValue
78

89
from app.telemetry import setup as telemetry_setup
910

1011
app = Flask(__name__)
1112
telemetry_setup(app, service_name="keep-app")
1213

14+
F = TypeVar("F", bound=Callable[..., ResponseReturnValue])
15+
16+
17+
def route(rule: str, **options: Any) -> Callable[[F], F]:
18+
return cast(Callable[[F], F], app.route(rule, **options))
19+
1320

1421
@contextmanager
1522
def record_route_metrics(route: str) -> Generator[None, None, None]:
@@ -24,13 +31,13 @@ def record_route_metrics(route: str) -> Generator[None, None, None]:
2431
)
2532

2633

27-
@app.route("/health")
34+
@route("/health")
2835
def health() -> Dict[str, str]:
2936
with record_route_metrics("health"):
3037
return {"status": "ok"}
3138

3239

33-
@app.route("/")
40+
@route("/")
3441
def index() -> str:
3542
with record_route_metrics("index"):
3643
cert_subject = request.headers.get("X-Client-Subject", "unknown") or "unknown"
@@ -44,7 +51,7 @@ def index() -> str:
4451
)
4552

4653

47-
@app.route("/step-up", methods=["POST"])
54+
@route("/step-up", methods=["POST"])
4855
def step_up() -> Tuple[Response, int]:
4956
with record_route_metrics("step_up"):
5057
return jsonify({"status": "step-up required"}), 202

0 commit comments

Comments
 (0)