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
protobuf>=3.6.0
yagrc>=1.1.1
typing-extensions>=4.3.0
package_dir =
=..
py_modules =

View file

@ -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

View file

@ -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