From c3272cf781b184ef53877baad43caeadd308cdc1 Mon Sep 17 00:00:00 2001 From: "Jack Boswell (boswelja)" Date: Sun, 11 Sep 2022 13:45:39 +1200 Subject: [PATCH] Add typing-extensions for proper TypedDict support Also updated UnwrappedHistory to expose its types --- packaging/setup.cfg | 1 + requirements.txt | 1 + starlink_grpc.py | 20 +++++++------------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/packaging/setup.cfg b/packaging/setup.cfg index 2c0b772..b740447 100644 --- a/packaging/setup.cfg +++ b/packaging/setup.cfg @@ -19,6 +19,7 @@ install_requires = grpcio>=1.12.0 protobuf>=3.6.0 yagrc>=1.1.1 + typing-extensions>=4.3.0 package_dir = =.. py_modules = diff --git a/requirements.txt b/requirements.txt index f1b25eb..f401847 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ paho-mqtt>=1.5.1 influxdb>=5.3.1 influxdb_client>=1.23.0 pypng>=0.0.20 +typing-extensions>=4.3.0 \ No newline at end of file diff --git a/starlink_grpc.py b/starlink_grpc.py index 55da404..68965c5 100644 --- a/starlink_grpc.py +++ b/starlink_grpc.py @@ -363,17 +363,8 @@ from itertools import chain import math import statistics from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, get_type_hints -try: - from typing import TypedDict, get_args -except ImportError: - # Python 3.7 does not have TypedDict, so fake it so the run time still - # works, even though static type checker probably will not. - def TypedDict(name, types): # pylint: disable=invalid-name - return type(name, (dict,), {"__annotations__": types}) - - def get_args(tp: Any) -> Tuple[Any, ...]: - return tp.__args__ - +from typing_extensions import TypedDict, get_args +from xmlrpc.client import Boolean import grpc @@ -549,7 +540,10 @@ class GrpcError(Exception): class UnwrappedHistory: - """Empty class for holding a copy of grpc history data.""" + """Class for holding a copy of grpc history data.""" + + unwrapped: bool + current: Any class ChannelContext: @@ -1031,7 +1025,7 @@ def concatenate_history(history1, history2, samples1: int = -1, start1: Optional print("WARNING: Appending discontiguous samples. Polling interval probably too short.") new_samples = size2 - unwrapped: Any = UnwrappedHistory() + unwrapped = UnwrappedHistory() for field in HISTORY_FIELDS: setattr(unwrapped, field, []) unwrapped.unwrapped = True