Partial fix for mypy issues

This commit is contained in:
Ian Renton
2026-09-20 20:42:16 +01:00
parent 93ea27510f
commit 203758fa2d
25 changed files with 244 additions and 147 deletions
+8 -2
View File
@@ -144,13 +144,14 @@ class APISpotHandler(tornado.web.RequestHandler):
return
# Reject if activity ref format incorrect for activity
ref_regex = get_ref_regex_for_activity(spot.sig) if spot.sig else None
if (
spot.sig
and spot.sig_refs
and len(spot.sig_refs) > 0
and spot.sig_refs[0].id
and get_ref_regex_for_activity(spot.sig)
and not re.match(get_ref_regex_for_activity(spot.sig), spot.sig_refs[0].id)
and ref_regex
and not re.match(ref_regex, spot.sig_refs[0].id)
):
self.set_status(422)
self.write(
@@ -202,6 +203,8 @@ class APISpotHandler(tornado.web.RequestHandler):
# Submit upstream if requested
upstream_warning = None
if submit_upstream and upstream_provider_name:
# spot.sig was already validated non-empty above, under the same submit_upstream/upstream_provider_name gate
assert spot.sig is not None
provider = self._find_provider(upstream_provider_name, spot.sig)
if provider:
try:
@@ -224,6 +227,8 @@ class APISpotHandler(tornado.web.RequestHandler):
# we were but it failed, we should still add it to our database anyway.
if not submit_upstream or upstream_warning:
spot.infer_missing()
assert self._spots is not None, "initialize() must be called before post()"
assert spot.id is not None, "infer_missing() always assigns an id"
self._spots.set(spot.id, spot)
if upstream_warning:
@@ -245,6 +250,7 @@ class APISpotHandler(tornado.web.RequestHandler):
def _find_provider(self, provider_name: str, activity: str) -> SpotProvider | None:
"""Find an enabled provider by name that can submit spots for the given activity."""
assert self._spot_providers is not None, "initialize() must be called before _find_provider()"
for p in self._spot_providers:
if p.enabled and p.name == provider_name and p.can_submit_spot(activity):
return p