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
+10 -5
View File
@@ -1,19 +1,24 @@
from __future__ import annotations
import logging
import re
from typing import Any
import simplejson
from pyhamtools import Callinfo
from pyhamtools.frequency import freq_to_band
from pyhamtools.locator import latlong_to_locator
from core.constants import BANDS, UNKNOWN_BAND
from core.data_store import DATA_STORE
from core.enums import MODE_ALIASES, Continent, Mode, ModeType
from data.band import Band
from data.callsign import Callsign, LocationSourceForCallsign
logger = logging.getLogger(__name__)
def safe_json_dumps(obj):
def safe_json_dumps(obj: Any) -> str:
"""Safe version of json.dumps that also converts objects to dicts so they can be output, and ignores NaN floats
which are invalid in JSON."""
@@ -59,7 +64,7 @@ def infer_mode_type_from_mode(mode: str) -> ModeType | None:
return None
def infer_band_from_freq(freq):
def infer_band_from_freq(freq: float) -> Band:
"""Infer a band from a frequency in Hz"""
for b in BANDS:
@@ -68,7 +73,7 @@ def infer_band_from_freq(freq):
return UNKNOWN_BAND
def infer_mode_from_frequency(freq):
def infer_mode_from_frequency(freq: float) -> Mode | None:
"""Infer a mode from the frequency (in Hz) according to the band plan. Just a guess really."""
try:
@@ -113,14 +118,14 @@ def infer_mode_from_frequency(freq):
return None
def get_flag_for_dxcc(dxcc):
def get_flag_for_dxcc(dxcc: int) -> str | None:
"""Get an emoji flag for a given DXCC entity ID"""
dxcc_data = DATA_STORE.dxcc_data.get(dxcc, None)
return dxcc_data["flag"] if dxcc_data else None
def get_callsign_object_from_pyhamtools_callinfo(callsign, callinfo):
def get_callsign_object_from_pyhamtools_callinfo(callsign: str, callinfo: Callinfo) -> Callsign:
"""Utility function to take the data provided by a PyHamTools CallInfo object and populate our own Callsign data
object from it"""