Skip to content

Commit 9202986

Browse files
authored
Update mypy and pylint (#39164)
1 parent 898a0be commit 9202986

File tree

17 files changed

+27
-47
lines changed

17 files changed

+27
-47
lines changed

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_quickpulse/_constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
_DEPENDENCY_FAILURE_RATE_NAME = (
2121
"azuremonitor.dependencycallsfailedsec",
2222
"\\ApplicationInsights\\Dependency Calls Failed/Sec",
23-
) # pylint: disable=line-too-long
23+
)
2424
_DEPENDENCY_DURATION_NAME = ("azuremonitor.dependencycallduration", "\\ApplicationInsights\\Dependency Call Duration")
2525
# Exception
2626
_EXCEPTION_RATE_NAME = ("azuremonitor.exceptionssec", "\\ApplicationInsights\\Exceptions/Sec")

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_quickpulse/_exporter.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class _UnsuccessfulQuickPulsePostError(Exception):
8383

8484
class _QuickpulseExporter(MetricExporter):
8585

86-
def __init__(self, **kwargs: Any) -> None: # pylint: disable=unused-argument
86+
def __init__(self, **kwargs: Any) -> None:
8787
"""Metric exporter for Quickpulse.
8888
8989
:param str connection_string: The connection string used for your Application Insights resource.
@@ -125,8 +125,8 @@ def __init__(self, **kwargs: Any) -> None: # pylint: disable=unused-argument
125125
def export(
126126
self,
127127
metrics_data: OTMetricsData,
128-
timeout_millis: float = 10_000, # pylint: disable=unused-argument
129-
**kwargs: Any, # pylint: disable=unused-argument
128+
timeout_millis: float = 10_000,
129+
**kwargs: Any,
130130
) -> MetricExportResult:
131131
"""Exports a batch of metric data
132132
@@ -171,7 +171,7 @@ def export(
171171
else:
172172
# Check if etag has changed
173173
etag = post_response._response_headers.get( # pylint: disable=protected-access
174-
_QUICKPULSE_ETAG_HEADER_NAME # pylint: disable=protected-access
174+
_QUICKPULSE_ETAG_HEADER_NAME
175175
)
176176
if etag and etag != configuration_etag:
177177
config = (
@@ -182,10 +182,10 @@ def export(
182182
# Update and apply configuration changes
183183
try:
184184
_update_filter_configuration(etag, config)
185-
except Exception: # pylint: disable=broad-except,invalid-name
185+
except Exception: # pylint: disable=broad-except
186186
_logger.exception("Exception occurred while updating filter config.")
187187
result = MetricExportResult.FAILURE
188-
except Exception: # pylint: disable=broad-except,invalid-name
188+
except Exception: # pylint: disable=broad-except
189189
_logger.exception("Exception occurred while publishing live metrics.")
190190
result = MetricExportResult.FAILURE
191191
finally:
@@ -209,8 +209,8 @@ def force_flush(
209209

210210
def shutdown(
211211
self,
212-
timeout_millis: float = 30_000, # pylint: disable=unused-argument
213-
**kwargs: Any, # pylint: disable=unused-argument
212+
timeout_millis: float = 30_000,
213+
**kwargs: Any,
214214
) -> None:
215215
"""Shuts down the exporter.
216216
@@ -239,7 +239,7 @@ def _ping(self, monitoring_data_point: MonitoringDataPoint) -> Optional[_Respons
239239
cls=_Response,
240240
)
241241
return ping_response # type: ignore
242-
except Exception: # pylint: disable=broad-except,invalid-name
242+
except Exception: # pylint: disable=broad-except
243243
_logger.exception("Exception occurred while pinging live metrics.")
244244
detach(token)
245245
return ping_response
@@ -300,7 +300,7 @@ def _ticker(self) -> None:
300300
_set_global_quickpulse_state(_QuickpulseState.PING_LONG)
301301
# Reset etag to default if not subscribed
302302
_set_quickpulse_etag("")
303-
except Exception: # pylint: disable=broad-except,invalid-name
303+
except Exception: # pylint: disable=broad-except
304304
_logger.exception("Exception occurred while reading live metrics ping response.")
305305
_set_quickpulse_etag("")
306306
# TODO: Implement redirect

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_quickpulse/_filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def _check_filters(filters: List[FilterInfo], data: _TelemetryData) -> bool:
133133
elif name in ("ResultCode", "ResponseCode", "Duration"):
134134
try:
135135
val = int(val)
136-
except Exception: # pylint: disable=broad-exception-caught,invalid-name
136+
except Exception: # pylint: disable=broad-exception-caught
137137
return False
138138
numerical_val = _filter_time_stamp_to_ms(comparand) if name == "Duration" else int(comparand)
139139
if numerical_val is None:

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_quickpulse/_state.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def _is_post_state():
9696

9797

9898
def _append_quickpulse_document(document: DocumentIngress):
99-
# pylint: disable=global-statement,global-variable-not-assigned
99+
# pylint: disable=global-variable-not-assigned
100100
global _QUICKPULSE_DOCUMENTS
101101
# Limit risk of memory leak by limiting doc length to something manageable
102102
if len(_QUICKPULSE_DOCUMENTS) > 20:
@@ -143,7 +143,6 @@ def _get_quickpulse_derived_metric_infos() -> Dict[TelemetryType, List[DerivedMe
143143

144144
# Used for initializing and setting projections when span/logs are recorded
145145
def _set_quickpulse_projection_map(metric_id: str, aggregation_type: AggregationType, value: float, count: int):
146-
# pylint: disable=global-statement
147146
# pylint: disable=global-variable-not-assigned
148147
global _QUICKPULSE_PROJECTION_MAP
149148
_QUICKPULSE_PROJECTION_MAP[metric_id] = (aggregation_type, value, count)
@@ -173,7 +172,6 @@ def _reset_quickpulse_projection_map():
173172

174173
# clears the projection map, usually called when config changes
175174
def _clear_quickpulse_projection_map():
176-
# pylint: disable=global-statement
177175
# pylint: disable=global-variable-not-assigned
178176
global _QUICKPULSE_PROJECTION_MAP
179177
_QUICKPULSE_PROJECTION_MAP.clear()

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_quickpulse/_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,6 @@ def _filter_time_stamp_to_ms(time_stamp: str) -> Optional[int]:
174174
+ float(minutes) * 60 * 1000 # minutes to milliseconds
175175
+ float(seconds) * 1000 # seconds to milliseconds
176176
)
177-
except Exception: # pylint: disable=broad-except,invalid-name
177+
except Exception: # pylint: disable=broad-except
178178
pass
179179
return total_milliseconds

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_quickpulse/_validate.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from azure.monitor.opentelemetry.exporter._quickpulse._utils import _filter_time_stamp_to_ms
1717

1818

19-
# pylint: disable=protected-access
2019
def _validate_derived_metric_info(metric_info: DerivedMetricInfo) -> bool:
2120
if not _validate_telemetry_type(metric_info.telemetry_type):
2221
return False
@@ -50,7 +49,7 @@ def _validate_telemetry_type(telemetry_type: str) -> bool:
5049
# Validate telemetry type
5150
try:
5251
telemetry_type = TelemetryType(telemetry_type)
53-
except Exception: # pylint: disable=broad-except,invalid-name
52+
except Exception: # pylint: disable=broad-except
5453
return False
5554
# Only REQUEST, DEPENDENCY, EXCEPTION, TRACE are supported
5655
# No filtering options in UX for PERFORMANCE_COUNTERS
@@ -104,7 +103,7 @@ def _validate_filter_predicate_and_comparand(filter: FilterInfo) -> bool:
104103
# Validate predicate type
105104
try:
106105
predicate = PredicateType(filter.predicate)
107-
except Exception: # pylint: disable=broad-except,invalid-name
106+
except Exception: # pylint: disable=broad-except
108107
return False
109108
if not comparand:
110109
return False
@@ -121,7 +120,7 @@ def _validate_filter_predicate_and_comparand(filter: FilterInfo) -> bool:
121120
try:
122121
# Response/ResultCode comparand should be interpreted as integer
123122
int(comparand)
124-
except Exception: # pylint: disable=broad-except,invalid-name
123+
except Exception: # pylint: disable=broad-except
125124
return False
126125
elif name == "Success":
127126
if predicate not in (PredicateType.EQUAL, PredicateType.NOT_EQUAL):

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_storage.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ def __enter__(self):
113113
def __exit__(self, type, value, traceback):
114114
self.close()
115115

116-
# pylint: disable=unused-variable
117116
def _maintenance_routine(self):
118117
try:
119118
# pylint: disable=unused-variable

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/_base.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ def _handle_transmit_from_storage(self, envelopes: List[TelemetryItem], result:
181181

182182
# pylint: disable=too-many-branches
183183
# pylint: disable=too-many-nested-blocks
184-
# pylint: disable=too-many-return-statements
185184
# pylint: disable=too-many-statements
186185
def _transmit(self, envelopes: List[TelemetryItem]) -> ExportResult:
187186
"""
@@ -256,7 +255,7 @@ def _transmit(self, envelopes: List[TelemetryItem]) -> ExportResult:
256255
url = urlparse(location)
257256
else:
258257
redirect_has_headers = False
259-
if redirect_has_headers and url.scheme and url.netloc:
258+
if redirect_has_headers and url.scheme and url.netloc: # pylint: disable=E0606
260259
# Change the host to the new redirected host
261260
self.client._config.host = "{}://{}".format(url.scheme, url.netloc) # pylint: disable=W0212
262261
# Attempt to export again
@@ -333,9 +332,9 @@ def _transmit(self, envelopes: List[TelemetryItem]) -> ExportResult:
333332

334333
shutdown_statsbeat_metrics()
335334
# pylint: disable=lost-exception
336-
return ExportResult.FAILED_NOT_RETRYABLE # pylint: disable=W0012,W0134
335+
return ExportResult.FAILED_NOT_RETRYABLE # pylint: disable=W0134
337336
# pylint: disable=lost-exception
338-
return result # pylint: disable=W0012,W0134
337+
return result # pylint: disable=W0134
339338

340339
# No spans to export
341340
self._consecutive_redirects = 0

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/logs/_exporter.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ def _convert_log_to_envelope(log_data: LogData) -> TelemetryItem:
130130
if log_record.attributes:
131131
exc_type = log_record.attributes.get(EXCEPTION_TYPE)
132132
exc_message = log_record.attributes.get(EXCEPTION_MESSAGE)
133-
# pylint: disable=line-too-long
134133
stack_trace = log_record.attributes.get(EXCEPTION_STACKTRACE)
135134
severity_level = _get_severity_level(log_record.severity_number)
136135

@@ -167,7 +166,6 @@ def _convert_log_to_envelope(log_data: LogData) -> TelemetryItem:
167166
properties=properties,
168167
exceptions=[exc_details],
169168
)
170-
# pylint: disable=line-too-long
171169
envelope.data = MonitorBase(base_data=data, base_type="ExceptionData")
172170
else: # Message telemetry
173171
envelope.name = _MESSAGE_ENVELOPE_NAME

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/metrics/_exporter.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ def __init__(self, **kwargs: Any) -> None:
7373
def export(
7474
self,
7575
metrics_data: OTMetricsData,
76-
timeout_millis: float = 10_000, # pylint: disable=unused-argument
77-
**kwargs: Any, # pylint: disable=unused-argument
76+
timeout_millis: float = 10_000,
77+
**kwargs: Any,
7878
) -> MetricExportResult:
7979
"""Exports a batch of metric data
8080
@@ -119,8 +119,8 @@ def force_flush(
119119

120120
def shutdown(
121121
self,
122-
timeout_millis: float = 30_000, # pylint: disable=unused-argument
123-
**kwargs: Any, # pylint: disable=unused-argument
122+
timeout_millis: float = 30_000,
123+
**kwargs: Any,
124124
) -> None:
125125
"""Shuts down the exporter.
126126
@@ -212,7 +212,6 @@ def _convert_point_to_envelope(
212212
return envelope
213213

214214

215-
# pylint: disable=protected-access
216215
def _handle_std_metric_envelope(
217216
envelope: TelemetryItem,
218217
name: str,

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/trace/_exporter.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ def from_connection_string(cls, conn_str: str, **kwargs: Any) -> "AzureMonitorTr
177177

178178
# pylint: disable=too-many-statements
179179
# pylint: disable=too-many-branches
180-
# pylint: disable=too-many-locals
181180
# pylint: disable=protected-access
182181
# mypy: disable-error-code="assignment,attr-defined,index,operator,union-attr"
183182
def _convert_span_to_envelope(span: ReadableSpan) -> TelemetryItem:
@@ -196,7 +195,6 @@ def _convert_span_to_envelope(span: ReadableSpan) -> TelemetryItem:
196195
envelope.tags[ContextTagKeys.AI_USER_ID] = span.attributes[SpanAttributes.ENDUSER_ID]
197196
if span.parent and span.parent.span_id:
198197
envelope.tags[ContextTagKeys.AI_OPERATION_PARENT_ID] = "{:016x}".format(span.parent.span_id)
199-
# pylint: disable=too-many-nested-blocks
200198
if span.kind in (SpanKind.CONSUMER, SpanKind.SERVER):
201199
envelope.name = _REQUEST_ENVELOPE_NAME
202200
data = RequestData(
@@ -482,7 +480,6 @@ def _convert_span_events_to_envelopes(span: ReadableSpan) -> Sequence[TelemetryI
482480
properties=properties,
483481
exceptions=[exc_details],
484482
)
485-
# pylint: disable=line-too-long
486483
envelope.data = MonitorBase(base_data=data, base_type="ExceptionData")
487484
else:
488485
envelope.name = _MESSAGE_ENVELOPE_NAME

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/trace/_sampling.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# pylint:disable=no-name-in-module
66
from fixedint import Int32
77

8-
# pylint:disable=W0611
98
from opentelemetry.context import Context
109
from opentelemetry.trace import Link, SpanKind, format_trace_id
1110
from opentelemetry.sdk.trace.sampling import (

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/statsbeat/_exporter.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
class _StatsBeatExporter(AzureMonitorMetricExporter):
1414

15-
# pylint: disable=protected-access
1615
def _point_to_envelope(
1716
self,
1817
point: DataPointT,

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/statsbeat/_statsbeat_metrics.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ def _get_azure_compute_metadata(self) -> bool:
230230
return True
231231

232232
# pylint: disable=unused-argument
233-
# pylint: disable=protected-access
234233
def _get_feature_metric(self, options: CallbackOptions) -> Iterable[Observation]:
235234
observations: List[Observation] = []
236235
# Check if it is time to observe long interval metrics
@@ -314,7 +313,6 @@ def init_non_initial_metrics(self):
314313
)
315314

316315
# pylint: disable=unused-argument
317-
# pylint: disable=protected-access
318316
def _get_success_count(self, options: CallbackOptions) -> Iterable[Observation]:
319317
# get_success_count is special in such that it is the indicator of when
320318
# a short interval collection has happened, which is why we increment
@@ -335,7 +333,6 @@ def _get_success_count(self, options: CallbackOptions) -> Iterable[Observation]:
335333
return observations
336334

337335
# pylint: disable=unused-argument
338-
# pylint: disable=protected-access
339336
def _get_failure_count(self, options: CallbackOptions) -> Iterable[Observation]:
340337
observations = []
341338
attributes = dict(_StatsbeatMetrics._COMMON_ATTRIBUTES)
@@ -350,7 +347,6 @@ def _get_failure_count(self, options: CallbackOptions) -> Iterable[Observation]:
350347
return observations
351348

352349
# pylint: disable=unused-argument
353-
# pylint: disable=protected-access
354350
def _get_average_duration(self, options: CallbackOptions) -> Iterable[Observation]:
355351
observations = []
356352
attributes = dict(_StatsbeatMetrics._COMMON_ATTRIBUTES)
@@ -367,7 +363,6 @@ def _get_average_duration(self, options: CallbackOptions) -> Iterable[Observatio
367363
return observations
368364

369365
# pylint: disable=unused-argument
370-
# pylint: disable=protected-access
371366
def _get_retry_count(self, options: CallbackOptions) -> Iterable[Observation]:
372367
observations = []
373368
attributes = dict(_StatsbeatMetrics._COMMON_ATTRIBUTES)
@@ -382,7 +377,6 @@ def _get_retry_count(self, options: CallbackOptions) -> Iterable[Observation]:
382377
return observations
383378

384379
# pylint: disable=unused-argument
385-
# pylint: disable=protected-access
386380
def _get_throttle_count(self, options: CallbackOptions) -> Iterable[Observation]:
387381
observations = []
388382
attributes = dict(_StatsbeatMetrics._COMMON_ATTRIBUTES)
@@ -397,7 +391,6 @@ def _get_throttle_count(self, options: CallbackOptions) -> Iterable[Observation]
397391
return observations
398392

399393
# pylint: disable=unused-argument
400-
# pylint: disable=protected-access
401394
def _get_exception_count(self, options: CallbackOptions) -> Iterable[Observation]:
402395
observations = []
403396
attributes = dict(_StatsbeatMetrics._COMMON_ATTRIBUTES)

sdk/monitor/azure-monitor-opentelemetry-exporter/samples/traces/django/sample/manage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def main():
2626
span_processor = BatchSpanProcessor(
2727
AzureMonitorTraceExporter.from_connection_string(os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"])
2828
)
29-
trace.get_tracer_provider().add_span_processor(span_processor)
29+
trace.get_tracer_provider().add_span_processor(span_processor) # type: ignore
3030

3131
try:
3232
from django.core.management import execute_from_command_line

sdk/monitor/azure-monitor-opentelemetry-exporter/samples/traces/django/sample/sample/asgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
span_processor = BatchSpanProcessor(
3232
AzureMonitorTraceExporter.from_connection_string(os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"])
3333
)
34-
trace.get_tracer_provider().add_span_processor(span_processor)
34+
trace.get_tracer_provider().add_span_processor(span_processor) # type: ignore
3535

3636
application = get_asgi_application()
3737

sdk/monitor/azure-monitor-opentelemetry-exporter/samples/traces/django/sample/sample/wsgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030
span_processor = BatchSpanProcessor(
3131
AzureMonitorTraceExporter.from_connection_string(os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"])
3232
)
33-
trace.get_tracer_provider().add_span_processor(span_processor)
33+
trace.get_tracer_provider().add_span_processor(span_processor) # type: ignore
3434

3535
application = get_wsgi_application()

0 commit comments

Comments
 (0)