From 5366ddf7708c931297cc1876b3fd58bf8c367319 Mon Sep 17 00:00:00 2001 From: Ian McEwen Date: Thu, 8 Aug 2024 09:43:43 -0700 Subject: [PATCH] Add/update some types to be at least as backwards-compatible as we can be --- meshtastic/analysis/__main__.py | 4 ++-- meshtastic/slog/arrow.py | 4 ++-- meshtastic/slog/slog.py | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/meshtastic/analysis/__main__.py b/meshtastic/analysis/__main__.py index c4d79e9..50505a6 100644 --- a/meshtastic/analysis/__main__.py +++ b/meshtastic/analysis/__main__.py @@ -2,7 +2,7 @@ import argparse import logging -from typing import cast +from typing import cast, List import dash_bootstrap_components as dbc # type: ignore[import-untyped] import numpy as np @@ -20,7 +20,7 @@ from ..slog import root_dir pd.options.mode.copy_on_write = True -def to_pmon_names(arr) -> list[str]: +def to_pmon_names(arr) -> List[str]: """Convert the power monitor state numbers to their corresponding names. arr (list): List of power monitor state numbers. diff --git a/meshtastic/slog/arrow.py b/meshtastic/slog/arrow.py index 4bb2e78..74fb5b5 100644 --- a/meshtastic/slog/arrow.py +++ b/meshtastic/slog/arrow.py @@ -3,7 +3,7 @@ import logging import threading import os -from typing import Optional +from typing import Optional, List import pyarrow as pa from pyarrow import feather @@ -20,7 +20,7 @@ class ArrowWriter: file_name (str): The name of the file to write to. """ self.sink = pa.OSFile(file_name, "wb") # type: ignore - self.new_rows: list[dict] = [] + self.new_rows: List[dict] = [] self.schema: Optional[pa.Schema] = None # haven't yet learned the schema self.writer: Optional[pa.RecordBatchStreamWriter] = None self._lock = threading.Condition() # Ensure only one thread writes at a time diff --git a/meshtastic/slog/slog.py b/meshtastic/slog/slog.py index 326bac6..6b09e4b 100644 --- a/meshtastic/slog/slog.py +++ b/meshtastic/slog/slog.py @@ -10,7 +10,7 @@ import time from dataclasses import dataclass from datetime import datetime from functools import reduce -from typing import Optional +from typing import Optional, List, Tuple import parse # type: ignore[import-untyped] import platformdirs @@ -39,10 +39,10 @@ class LogDef: """Log definition.""" code: str # i.e. PM or B or whatever... see meshtastic slog documentation - fields: list[tuple[str, pa.DataType]] # A list of field names and their arrow types + fields: List[Tuple[str, pa.DataType]] # A list of field names and their arrow types format: parse.Parser # A format string that can be used to parse the arguments - def __init__(self, code: str, fields: list[tuple[str, pa.DataType]]) -> None: + def __init__(self, code: str, fields: List[Tuple[str, pa.DataType]]) -> None: """Initialize the LogDef object. code (str): The code. @@ -93,7 +93,7 @@ class PowerLogger: ) self.thread.start() - def store_current_reading(self, now: datetime | None = None) -> None: + def store_current_reading(self, now: Optional[datetime] = None) -> None: """Store current power measurement.""" if now is None: now = datetime.now() @@ -133,7 +133,7 @@ class StructuredLogger: self, client: MeshInterface, dir_path: str, - power_logger: PowerLogger | None = None, + power_logger: Optional[PowerLogger] = None, include_raw=True, ) -> None: """Initialize the StructuredLogger object.