Merge pull request #64 from boswelja/typing-extensions

Introduce typing-extensions for proper TypedDict support on Python 3.7
This commit is contained in:
sparky8512 2022-09-12 07:51:28 -07:00 committed by GitHub
commit 24b8f95792
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 15 deletions

View file

@ -11,7 +11,8 @@ pip3 install \
certifi==2020.12.5 chardet==4.0.0 idna==2.10 urllib3==1.26.4 \
six==1.15.0 msgpack==1.0.2 \
influxdb_client==1.24.0 rx==3.2.0 \
yagrc==1.1.1 grpcio-reflection==1.36.1 protobuf==3.15.6
yagrc==1.1.1 grpcio-reflection==1.36.1 protobuf==3.15.6 \
typing-extensions==4.3.0
ADD . /app
WORKDIR /app

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

@ -362,18 +362,8 @@ period.
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 import Dict, Iterable, List, Optional, Sequence, Tuple, get_type_hints
from typing_extensions import TypedDict, get_args
import grpc
@ -549,7 +539,9 @@ 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
class ChannelContext:
@ -1031,7 +1023,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