Skip to content

Commit 8e6c5a2

Browse files
committed
Convert list[object] to List[object] to support python 3.8
1 parent 04d14b2 commit 8e6c5a2

File tree

6 files changed

+41
-34
lines changed

6 files changed

+41
-34
lines changed

contract-tests/images/mock-collector/mock_collector_client.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from datetime import datetime, timedelta
44
from logging import Logger, getLogger
55
from time import sleep
6-
from typing import Callable, TypeVar
6+
from typing import Callable, TypeVar, List
77

88
from google.protobuf.internal.containers import RepeatedScalarFieldContainer
99
from grpc import Channel, insecure_channel
@@ -62,46 +62,46 @@ def clear_signals(self) -> None:
6262
"""Clear all the signals in the backend collector"""
6363
self.client.clear(ClearRequest())
6464

65-
def get_traces(self) -> list[ResourceScopeSpan]:
65+
def get_traces(self) -> List[ResourceScopeSpan]:
6666
"""Get all traces that are currently stored in the collector
6767
6868
Returns:
6969
List of `ResourceScopeSpan` which is essentially a flat list containing all the spans and their related
7070
scope and resources.
7171
"""
7272

73-
def get_export() -> list[ExportTraceServiceRequest]:
73+
def get_export() -> List[ExportTraceServiceRequest]:
7474
response: GetTracesResponse = self.client.get_traces(GetTracesRequest())
7575
serialized_traces: RepeatedScalarFieldContainer[bytes] = response.traces
7676
return list(map(ExportTraceServiceRequest.FromString, serialized_traces))
7777

78-
def wait_condition(exported: list[ExportTraceServiceRequest], current: list[ExportTraceServiceRequest]) -> bool:
78+
def wait_condition(exported: List[ExportTraceServiceRequest], current: List[ExportTraceServiceRequest]) -> bool:
7979
return 0 < len(exported) == len(current)
8080

81-
exported_traces: list[ExportTraceServiceRequest] = _wait_for_content(get_export, wait_condition)
82-
spans: list[ResourceScopeSpan] = []
81+
exported_traces: List[ExportTraceServiceRequest] = _wait_for_content(get_export, wait_condition)
82+
spans: List[ResourceScopeSpan] = []
8383
for exported_trace in exported_traces:
8484
for resource_span in exported_trace.resource_spans:
8585
for scope_span in resource_span.scope_spans:
8686
for span in scope_span.spans:
8787
spans.append(ResourceScopeSpan(resource_span, scope_span, span))
8888
return spans
8989

90-
def get_metrics(self, present_metrics: set[str]) -> list[ResourceScopeMetric]:
90+
def get_metrics(self, present_metrics: set[str]) -> List[ResourceScopeMetric]:
9191
"""Get all metrics that are currently stored in the mock collector.
9292
9393
Returns:
9494
List of `ResourceScopeMetric` which is a flat list containing all metrics and their related scope and
9595
resources.
9696
"""
9797

98-
def get_export() -> list[ExportMetricsServiceRequest]:
98+
def get_export() -> List[ExportMetricsServiceRequest]:
9999
response: GetMetricsResponse = self.client.get_metrics(GetMetricsRequest())
100100
serialized_metrics: RepeatedScalarFieldContainer[bytes] = response.metrics
101101
return list(map(ExportMetricsServiceRequest.FromString, serialized_metrics))
102102

103103
def wait_condition(
104-
exported: list[ExportMetricsServiceRequest], current: list[ExportMetricsServiceRequest]
104+
exported: List[ExportMetricsServiceRequest], current: List[ExportMetricsServiceRequest]
105105
) -> bool:
106106
received_metrics: set[str] = set()
107107
for exported_metric in current:
@@ -111,8 +111,8 @@ def wait_condition(
111111
received_metrics.add(metric.name)
112112
return 0 < len(exported) == len(current) and present_metrics.issubset(received_metrics)
113113

114-
exported_metrics: list[ExportMetricsServiceRequest] = _wait_for_content(get_export, wait_condition)
115-
metrics: list[ResourceScopeMetric] = []
114+
exported_metrics: List[ExportMetricsServiceRequest] = _wait_for_content(get_export, wait_condition)
115+
metrics: List[ResourceScopeMetric] = []
116116
for exported_metric in exported_metrics:
117117
for resource_metric in exported_metric.resource_metrics:
118118
for scope_metric in resource_metric.scope_metrics:
@@ -121,14 +121,14 @@ def wait_condition(
121121
return metrics
122122

123123

124-
def _wait_for_content(get_export: Callable[[], list[T]], wait_condition: Callable[[list[T], list[T]], bool]) -> list[T]:
124+
def _wait_for_content(get_export: Callable[[], List[T]], wait_condition: Callable[[list[T], List[T]], bool]) -> List[T]:
125125
# Verify that there is no more data to be received
126126
deadline: datetime = datetime.now() + _TIMEOUT_DELAY
127-
exported: list[T] = []
127+
exported: List[T] = []
128128

129129
while deadline > datetime.now():
130130
try:
131-
current_exported: list[T] = get_export()
131+
current_exported: List[T] = get_export()
132132
if wait_condition(exported, current_exported):
133133
return current_exported
134134
exported = current_exported

contract-tests/images/mock-collector/mock_collector_metrics_service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
from queue import Queue
4+
from typing import List
45

56
from grpc import ServicerContext
67
from typing_extensions import override
@@ -15,7 +16,7 @@
1516
class MockCollectorMetricsService(MetricsServiceServicer):
1617
_export_requests: Queue = Queue(maxsize=-1)
1718

18-
def get_requests(self) -> list[ExportMetricsServiceRequest]:
19+
def get_requests(self) -> List[ExportMetricsServiceRequest]:
1920
with self._export_requests.mutex:
2021
return list(self._export_requests.queue)
2122

contract-tests/images/mock-collector/mock_collector_service.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
3+
from typing import List
4+
35
from grpc import ServicerContext
46
from mock_collector_metrics_service import MockCollectorMetricsService
57
from mock_collector_service_pb2 import (
@@ -37,14 +39,14 @@ def clear(self, request: ClearRequest, context: ServicerContext) -> ClearRespons
3739

3840
@override
3941
def get_traces(self, request: GetTracesRequest, context: ServicerContext) -> GetTracesResponse:
40-
trace_requests: list[ExportTraceServiceRequest] = self.trace_collector.get_requests()
41-
traces: list[bytes] = list(map(ExportTraceServiceRequest.SerializeToString, trace_requests))
42+
trace_requests: List[ExportTraceServiceRequest] = self.trace_collector.get_requests()
43+
traces: List[bytes] = list(map(ExportTraceServiceRequest.SerializeToString, trace_requests))
4244
response: GetTracesResponse = GetTracesResponse(traces=traces)
4345
return response
4446

4547
@override
4648
def get_metrics(self, request: GetMetricsRequest, context: ServicerContext) -> GetMetricsResponse:
47-
metric_requests: list[ExportMetricsServiceRequest] = self.metrics_collector.get_requests()
48-
metrics: list[bytes] = list(map(ExportTraceServiceRequest.SerializeToString, metric_requests))
49+
metric_requests: List[ExportMetricsServiceRequest] = self.metrics_collector.get_requests()
50+
metrics: List[bytes] = list(map(ExportTraceServiceRequest.SerializeToString, metric_requests))
4951
response: GetMetricsResponse = GetMetricsResponse(metrics=metrics)
5052
return response

contract-tests/images/mock-collector/mock_collector_trace_service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
from queue import Queue
4+
from typing import List
45

56
from grpc import ServicerContext
67
from typing_extensions import override
@@ -15,7 +16,7 @@
1516
class MockCollectorTraceService(TraceServiceServicer):
1617
_export_requests: Queue = Queue(maxsize=-1)
1718

18-
def get_requests(self) -> list[ExportTraceServiceRequest]:
19+
def get_requests(self) -> List[ExportTraceServiceRequest]:
1920
with self._export_requests.mutex:
2021
return list(self._export_requests.queue)
2122

contract-tests/tests/test/amazon/base/contract_test_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
3+
from typing import List
34
from unittest import TestCase
45

56
from docker import DockerClient
@@ -86,7 +87,7 @@ def get_application_port(self) -> int:
8687
def get_application_extra_environment_variables(self) -> dict[str, str]:
8788
return {}
8889

89-
def get_application_network_aliases(self) -> list[str]:
90+
def get_application_network_aliases(self) -> List[str]:
9091
return []
9192

9293
def get_application_image_name(self) -> str:

contract-tests/tests/test/amazon/requests/requests_test.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
3+
from typing import List
4+
35
from mock_collector_client import ResourceScopeMetric, ResourceScopeSpan
46
from requests import Response, request
57
from typing_extensions import override
@@ -27,7 +29,7 @@ def get_application_image_name(self) -> str:
2729
return "aws-appsignals-tests-requests-app"
2830

2931
@override
30-
def get_application_network_aliases(self) -> list[str]:
32+
def get_application_network_aliases(self) -> List[str]:
3133
"""
3234
This will be the target hostname of the clients making http requests in the application image, so that they
3335
don't use localhost.
@@ -70,21 +72,21 @@ def do_test_requests(
7072

7173
self.assertEqual(status_code, response.status_code)
7274

73-
resource_scope_spans: list[ResourceScopeSpan] = self._mock_collector_client.get_traces()
75+
resource_scope_spans: List[ResourceScopeSpan] = self._mock_collector_client.get_traces()
7476
self._assert_aws_span_attributes(resource_scope_spans, method, path)
7577
self._assert_semantic_conventions_span_attributes(resource_scope_spans, method, path, status_code)
7678

77-
metrics: list[ResourceScopeMetric] = self._mock_collector_client.get_metrics(
79+
metrics: List[ResourceScopeMetric] = self._mock_collector_client.get_metrics(
7880
{LATENCY_METRIC, ERROR_METRIC, FAULT_METRIC}
7981
)
8082
self._assert_metric_attributes(metrics, method, path, LATENCY_METRIC, 5000)
8183
self._assert_metric_attributes(metrics, method, path, ERROR_METRIC, expected_error)
8284
self._assert_metric_attributes(metrics, method, path, FAULT_METRIC, expected_fault)
8385

8486
def _assert_aws_span_attributes(
85-
self, resource_scope_spans: list[ResourceScopeSpan], method: str, path: str
87+
self, resource_scope_spans: List[ResourceScopeSpan], method: str, path: str
8688
) -> None:
87-
target_spans: list[Span] = []
89+
target_spans: List[Span] = []
8890
for resource_scope_span in resource_scope_spans:
8991
# pylint: disable=no-member
9092
if resource_scope_span.span.kind == Span.SPAN_KIND_CLIENT:
@@ -93,7 +95,7 @@ def _assert_aws_span_attributes(
9395
self.assertEqual(len(target_spans), 1)
9496
self._assert_aws_attributes(target_spans[0].attributes, method, path)
9597

96-
def _assert_aws_attributes(self, attributes_list: list[KeyValue], method: str, endpoint: str) -> None:
98+
def _assert_aws_attributes(self, attributes_list: List[KeyValue], method: str, endpoint: str) -> None:
9799
attributes_dict: dict[str, AnyValue] = self._get_attributes_dict(attributes_list)
98100
self._assert_str_attribute(attributes_dict, AWS_LOCAL_SERVICE, self.get_application_otel_service_name())
99101
# InternalOperation as OTEL does not instrument the basic server we are using, so the client span is a local
@@ -106,7 +108,7 @@ def _assert_aws_attributes(self, attributes_list: list[KeyValue], method: str, e
106108
# See comment above AWS_LOCAL_OPERATION
107109
self._assert_str_attribute(attributes_dict, AWS_SPAN_KIND, "LOCAL_ROOT")
108110

109-
def _get_attributes_dict(self, attributes_list: list[KeyValue]) -> dict[str, AnyValue]:
111+
def _get_attributes_dict(self, attributes_list: List[KeyValue]) -> dict[str, AnyValue]:
110112
attributes_dict: dict[str, AnyValue] = {}
111113
for attribute in attributes_list:
112114
key: str = attribute.key
@@ -129,9 +131,9 @@ def _assert_int_attribute(self, attributes_dict: dict[str, AnyValue], key: str,
129131
self.assertEqual(expected_value, actual_value.int_value)
130132

131133
def _assert_semantic_conventions_span_attributes(
132-
self, resource_scope_spans: list[ResourceScopeSpan], method: str, path: str, status_code: int
134+
self, resource_scope_spans: List[ResourceScopeSpan], method: str, path: str, status_code: int
133135
) -> None:
134-
target_spans: list[Span] = []
136+
target_spans: List[Span] = []
135137
for resource_scope_span in resource_scope_spans:
136138
# pylint: disable=no-member
137139
if resource_scope_span.span.kind == Span.SPAN_KIND_CLIENT:
@@ -142,7 +144,7 @@ def _assert_semantic_conventions_span_attributes(
142144
self._assert_semantic_conventions_attributes(target_spans[0].attributes, method, path, status_code)
143145

144146
def _assert_semantic_conventions_attributes(
145-
self, attributes_list: list[KeyValue], method: str, endpoint: str, status_code: int
147+
self, attributes_list: List[KeyValue], method: str, endpoint: str, status_code: int
146148
) -> None:
147149
attributes_dict: dict[str, AnyValue] = self._get_attributes_dict(attributes_list)
148150
# TODO: requests instrumentation is not populating net peer attributes
@@ -156,20 +158,20 @@ def _assert_semantic_conventions_attributes(
156158

157159
def _assert_metric_attributes(
158160
self,
159-
resource_scope_metrics: list[ResourceScopeMetric],
161+
resource_scope_metrics: List[ResourceScopeMetric],
160162
method: str,
161163
path: str,
162164
metric_name: str,
163165
expected_sum: float,
164166
) -> None:
165-
target_metrics: list[Metric] = []
167+
target_metrics: List[Metric] = []
166168
for resource_scope_metric in resource_scope_metrics:
167169
if resource_scope_metric.metric.name == metric_name:
168170
target_metrics.append(resource_scope_metric.metric)
169171

170172
self.assertEqual(len(target_metrics), 1)
171173
target_metric: Metric = target_metrics[0]
172-
dp_list: list[ExponentialHistogramDataPoint] = target_metric.exponential_histogram.data_points
174+
dp_list: List[ExponentialHistogramDataPoint] = target_metric.exponential_histogram.data_points
173175

174176
self.assertEqual(len(dp_list), 2)
175177
dp: ExponentialHistogramDataPoint = dp_list[0]

0 commit comments

Comments
 (0)