mypy: fix up typing

This commit is contained in:
Iain Learmonth 2022-08-12 12:24:56 +01:00
parent 6c88a57ad5
commit 6423d93519
6 changed files with 13 additions and 10 deletions

View file

@ -1,7 +1,7 @@
from datetime import datetime, timedelta
import logging
from abc import abstractmethod
from typing import Tuple, List, Callable
from typing import Tuple, List, Callable, Optional
from app.extensions import db
from app.models.activity import Activity
@ -10,6 +10,9 @@ from app.terraform import BaseAutomation
class BlockBridgeAutomation(BaseAutomation):
ips: List[str]
fingerprints: List[str]
hashed_fingerprints: List[str]
patterns: List[str]
def __init__(self) -> None:
@ -21,7 +24,7 @@ class BlockBridgeAutomation(BaseAutomation):
self.hashed_fingerprints = []
super().__init__()
def perform_deprecations(self, ids: List[str], bridge_select_func: Callable[[str], Bridge]
def perform_deprecations(self, ids: List[str], bridge_select_func: Callable[[str], Optional[Bridge]]
) -> List[Tuple[str, str]]:
rotated = []
for id_ in ids:
@ -80,7 +83,7 @@ class BlockBridgeAutomation(BaseAutomation):
"""
def get_bridge_by_ip(ip: str) -> Bridge:
def get_bridge_by_ip(ip: str) -> Optional[Bridge]:
return Bridge.query.filter( # type: ignore[no-any-return]
Bridge.deprecated.is_(None),
Bridge.destroyed.is_(None),
@ -88,7 +91,7 @@ def get_bridge_by_ip(ip: str) -> Bridge:
).first()
def get_bridge_by_fingerprint(fingerprint: str) -> Bridge:
def get_bridge_by_fingerprint(fingerprint: str) -> Optional[Bridge]:
return Bridge.query.filter( # type: ignore[no-any-return]
Bridge.deprecated.is_(None),
Bridge.destroyed.is_(None),
@ -96,7 +99,7 @@ def get_bridge_by_fingerprint(fingerprint: str) -> Bridge:
).first()
def get_bridge_by_hashed_fingerprint(hashed_fingerprint: str) -> Bridge:
def get_bridge_by_hashed_fingerprint(hashed_fingerprint: str) -> Optional[Bridge]:
return Bridge.query.filter( # type: ignore[no-any-return]
Bridge.deprecated.is_(None),
Bridge.destroyed.is_(None),