Add typing-extensions for proper TypedDict support

Also updated UnwrappedHistory to expose its types
This commit is contained in:
Jack Boswell (boswelja) 2022-09-11 13:45:39 +12:00
parent 6a186b6e3b
commit c3272cf781
3 changed files with 9 additions and 13 deletions

View file

@ -19,6 +19,7 @@ install_requires =
grpcio>=1.12.0 grpcio>=1.12.0
protobuf>=3.6.0 protobuf>=3.6.0
yagrc>=1.1.1 yagrc>=1.1.1
typing-extensions>=4.3.0
package_dir = package_dir =
=.. =..
py_modules = py_modules =

View file

@ -6,3 +6,4 @@ paho-mqtt>=1.5.1
influxdb>=5.3.1 influxdb>=5.3.1
influxdb_client>=1.23.0 influxdb_client>=1.23.0
pypng>=0.0.20 pypng>=0.0.20
typing-extensions>=4.3.0

View file

@ -363,17 +363,8 @@ from itertools import chain
import math import math
import statistics import statistics
from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, get_type_hints from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, get_type_hints
try: from typing_extensions import TypedDict, get_args
from typing import TypedDict, get_args from xmlrpc.client import Boolean
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__
import grpc import grpc
@ -549,7 +540,10 @@ class GrpcError(Exception):
class UnwrappedHistory: 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: 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.") print("WARNING: Appending discontiguous samples. Polling interval probably too short.")
new_samples = size2 new_samples = size2
unwrapped: Any = UnwrappedHistory() unwrapped = UnwrappedHistory()
for field in HISTORY_FIELDS: for field in HISTORY_FIELDS:
setattr(unwrapped, field, []) setattr(unwrapped, field, [])
unwrapped.unwrapped = True unwrapped.unwrapped = True