mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-21 06:47:42 +00:00
Autogenerated type safety parameterisation of all methods
This commit is contained in:
+10
-5
@@ -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"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user