Autogenerated type safety parameterisation of all methods

This commit is contained in:
Ian Renton
2026-09-20 20:02:19 +01:00
parent 6037e742cc
commit 324dd1414b
132 changed files with 1228 additions and 706 deletions
+7 -5
View File
@@ -1,3 +1,5 @@
from __future__ import annotations
from collections import deque
from datetime import datetime, timedelta
@@ -10,12 +12,12 @@ class WebServerMetrics:
"""Tracker for web server metrics. Stores the times pages and API endpoints were accessed for an hour, so we
can display the rate of requests per hour, and also updates the equivalent Prometheus counters."""
def __init__(self):
def __init__(self) -> None:
self.status = "Starting"
self._page_access_times = deque()
self._api_access_times = deque()
self._page_access_times: deque[datetime] = deque()
self._api_access_times: deque[datetime] = deque()
def record(self, path: str, status_code: int):
def record(self, path: str, status_code: int) -> None:
"""Records data for a request, depending on whether it's a page, API, or other request, and making sure
the response code isn't 404. Also sets the status of the web server."""
@@ -37,7 +39,7 @@ class WebServerMetrics:
return self._count_and_prune_last_hour(self._api_access_times)
@staticmethod
def _count_and_prune_last_hour(access_times: deque) -> int:
def _count_and_prune_last_hour(access_times: deque[datetime]) -> int:
cutoff = datetime.now(pytz.UTC) - timedelta(hours=1)
while access_times and access_times[0] < cutoff:
access_times.popleft()