Skip to content

Commit afc3ace

Browse files
authored
Bump black to 24.3.0 (open-telemetry#3871)
1 parent 7c67637 commit afc3ace

File tree

17 files changed

+156
-127
lines changed

17 files changed

+156
-127
lines changed

.flake8

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ ignore =
1212
# allow whitespace before ':' (https://github.com/psf/black#slices)
1313
E203
1414

15+
# conflicts with black
16+
E701
17+
E704
18+
1519
exclude =
1620
.bzr
1721
.git

dev-requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pylint==3.0.2
22
flake8==6.1.0
33
isort==5.12.0
4-
black==22.3.0
4+
black==24.3.0
55
httpretty==1.1.4
66
mypy==1.9.0
77
sphinx==7.1.2

exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/trace_exporter/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ def translate_to_collector(spans: Sequence[ReadableSpan]):
133133
collector_span.parent_span_id = parent_id.to_bytes(8, "big")
134134

135135
if span.context.trace_state is not None:
136-
for (key, value) in span.context.trace_state.items():
136+
for key, value in span.context.trace_state.items():
137137
collector_span.tracestate.entries.add(key=key, value=value)
138138

139139
if span.attributes:
140-
for (key, value) in span.attributes.items():
140+
for key, value in span.attributes.items():
141141
utils.add_proto_attribute_value(
142142
collector_span.attributes, key, value
143143
)
@@ -150,7 +150,7 @@ def translate_to_collector(spans: Sequence[ReadableSpan]):
150150
)
151151

152152
if event.attributes:
153-
for (key, value) in event.attributes.items():
153+
for key, value in event.attributes.items():
154154
utils.add_proto_attribute_value(
155155
collector_annotation.attributes, key, value
156156
)
@@ -183,7 +183,7 @@ def translate_to_collector(spans: Sequence[ReadableSpan]):
183183
)
184184

185185
if link.attributes:
186-
for (key, value) in link.attributes.items():
186+
for key, value in link.attributes.items():
187187
utils.add_proto_attribute_value(
188188
collector_span_link.attributes, key, value
189189
)

exporter/opentelemetry-exporter-prometheus/src/opentelemetry/exporter/prometheus/__init__.py

+24-24
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ def collect(self) -> None:
196196
self._target_info = self._create_info_metric(
197197
_TARGET_INFO_NAME, _TARGET_INFO_DESCRIPTION, attributes
198198
)
199-
metric_family_id_metric_family[
200-
_TARGET_INFO_NAME
201-
] = self._target_info
199+
metric_family_id_metric_family[_TARGET_INFO_NAME] = (
200+
self._target_info
201+
)
202202

203203
while self._metrics_datas:
204204
self._translate_to_prometheus(
@@ -294,13 +294,13 @@ def _translate_to_prometheus(
294294
)
295295

296296
if metric_family_id not in metric_family_id_metric_family:
297-
metric_family_id_metric_family[
298-
metric_family_id
299-
] = CounterMetricFamily(
300-
name=metric_name,
301-
documentation=metric_description,
302-
labels=label_keys,
303-
unit=metric.unit,
297+
metric_family_id_metric_family[metric_family_id] = (
298+
CounterMetricFamily(
299+
name=metric_name,
300+
documentation=metric_description,
301+
labels=label_keys,
302+
unit=metric.unit,
303+
)
304304
)
305305
metric_family_id_metric_family[
306306
metric_family_id
@@ -318,13 +318,13 @@ def _translate_to_prometheus(
318318
metric_family_id
319319
not in metric_family_id_metric_family.keys()
320320
):
321-
metric_family_id_metric_family[
322-
metric_family_id
323-
] = GaugeMetricFamily(
324-
name=metric_name,
325-
documentation=metric_description,
326-
labels=label_keys,
327-
unit=metric.unit,
321+
metric_family_id_metric_family[metric_family_id] = (
322+
GaugeMetricFamily(
323+
name=metric_name,
324+
documentation=metric_description,
325+
labels=label_keys,
326+
unit=metric.unit,
327+
)
328328
)
329329
metric_family_id_metric_family[
330330
metric_family_id
@@ -339,13 +339,13 @@ def _translate_to_prometheus(
339339
metric_family_id
340340
not in metric_family_id_metric_family.keys()
341341
):
342-
metric_family_id_metric_family[
343-
metric_family_id
344-
] = HistogramMetricFamily(
345-
name=metric_name,
346-
documentation=metric_description,
347-
labels=label_keys,
348-
unit=metric.unit,
342+
metric_family_id_metric_family[metric_family_id] = (
343+
HistogramMetricFamily(
344+
name=metric_name,
345+
documentation=metric_description,
346+
labels=label_keys,
347+
unit=metric.unit,
348+
)
349349
)
350350
metric_family_id_metric_family[
351351
metric_family_id

opentelemetry-api/tests/propagators/test_w3cbaggagepropagator.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,13 @@ def test_header_max_entries_skip_invalid_entry(self):
134134
self._extract(
135135
",".join(
136136
[
137-
f"key{index}=value{index}"
138-
if index != 2
139-
else (
140-
f"key{index}="
141-
f"value{'s' * (W3CBaggagePropagator._MAX_PAIR_LENGTH + 1)}"
137+
(
138+
f"key{index}=value{index}"
139+
if index != 2
140+
else (
141+
f"key{index}="
142+
f"value{'s' * (W3CBaggagePropagator._MAX_PAIR_LENGTH + 1)}"
143+
)
142144
)
143145
for index in range(
144146
W3CBaggagePropagator._MAX_PAIRS + 1
@@ -162,9 +164,11 @@ def test_header_max_entries_skip_invalid_entry(self):
162164
self._extract(
163165
",".join(
164166
[
165-
f"key{index}=value{index}"
166-
if index != 2
167-
else f"key{index}xvalue{index}"
167+
(
168+
f"key{index}=value{index}"
169+
if index != 2
170+
else f"key{index}xvalue{index}"
171+
)
168172
for index in range(
169173
W3CBaggagePropagator._MAX_PAIRS + 1
170174
)

opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,21 @@ def _import_exporters(
265265
metric_exporters = {}
266266
log_exporters = {}
267267

268-
for (exporter_name, exporter_impl,) in _import_config_components(
268+
for (
269+
exporter_name,
270+
exporter_impl,
271+
) in _import_config_components(
269272
trace_exporter_names, "opentelemetry_traces_exporter"
270273
):
271274
if issubclass(exporter_impl, SpanExporter):
272275
trace_exporters[exporter_name] = exporter_impl
273276
else:
274277
raise RuntimeError(f"{exporter_name} is not a trace exporter")
275278

276-
for (exporter_name, exporter_impl,) in _import_config_components(
279+
for (
280+
exporter_name,
281+
exporter_impl,
282+
) in _import_config_components(
277283
metric_exporter_names, "opentelemetry_metrics_exporter"
278284
):
279285
# The metric exporter components may be push MetricExporter or pull exporters which
@@ -283,7 +289,10 @@ def _import_exporters(
283289
else:
284290
raise RuntimeError(f"{exporter_name} is not a metric exporter")
285291

286-
for (exporter_name, exporter_impl,) in _import_config_components(
292+
for (
293+
exporter_name,
294+
exporter_impl,
295+
) in _import_config_components(
287296
log_exporter_names, "opentelemetry_logs_exporter"
288297
):
289298
if issubclass(exporter_impl, LogExporter):
@@ -360,9 +369,9 @@ def _initialize_components(auto_instrumentation_version):
360369
auto_resource = {}
361370
# populate version if using auto-instrumentation
362371
if auto_instrumentation_version:
363-
auto_resource[
364-
ResourceAttributes.TELEMETRY_AUTO_VERSION
365-
] = auto_instrumentation_version
372+
auto_resource[ResourceAttributes.TELEMETRY_AUTO_VERSION] = (
373+
auto_instrumentation_version
374+
)
366375
resource = Resource.create(auto_resource)
367376

368377
_init_tracing(

opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -202,22 +202,26 @@ def to_json(self, indent=4) -> str:
202202
"body": self.body,
203203
"severity_number": repr(self.severity_number),
204204
"severity_text": self.severity_text,
205-
"attributes": dict(self.attributes)
206-
if bool(self.attributes)
207-
else None,
205+
"attributes": (
206+
dict(self.attributes) if bool(self.attributes) else None
207+
),
208208
"dropped_attributes": self.dropped_attributes,
209209
"timestamp": ns_to_iso_str(self.timestamp),
210210
"observed_timestamp": ns_to_iso_str(self.observed_timestamp),
211-
"trace_id": f"0x{format_trace_id(self.trace_id)}"
212-
if self.trace_id is not None
213-
else "",
214-
"span_id": f"0x{format_span_id(self.span_id)}"
215-
if self.span_id is not None
216-
else "",
211+
"trace_id": (
212+
f"0x{format_trace_id(self.trace_id)}"
213+
if self.trace_id is not None
214+
else ""
215+
),
216+
"span_id": (
217+
f"0x{format_span_id(self.span_id)}"
218+
if self.span_id is not None
219+
else ""
220+
),
217221
"trace_flags": self.trace_flags,
218-
"resource": repr(self.resource.attributes)
219-
if self.resource
220-
else "",
222+
"resource": (
223+
repr(self.resource.attributes) if self.resource else ""
224+
),
221225
},
222226
indent=indent,
223227
)

opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/export/__init__.py

+29-31
Original file line numberDiff line numberDiff line change
@@ -247,27 +247,27 @@ def __init__(
247247
if typ is Counter:
248248
self._instrument_class_temporality[_Counter] = temporality
249249
elif typ is UpDownCounter:
250-
self._instrument_class_temporality[
251-
_UpDownCounter
252-
] = temporality
250+
self._instrument_class_temporality[_UpDownCounter] = (
251+
temporality
252+
)
253253
elif typ is Histogram:
254-
self._instrument_class_temporality[
255-
_Histogram
256-
] = temporality
254+
self._instrument_class_temporality[_Histogram] = (
255+
temporality
256+
)
257257
elif typ is Gauge:
258258
self._instrument_class_temporality[_Gauge] = temporality
259259
elif typ is ObservableCounter:
260-
self._instrument_class_temporality[
261-
_ObservableCounter
262-
] = temporality
260+
self._instrument_class_temporality[_ObservableCounter] = (
261+
temporality
262+
)
263263
elif typ is ObservableUpDownCounter:
264264
self._instrument_class_temporality[
265265
_ObservableUpDownCounter
266266
] = temporality
267267
elif typ is ObservableGauge:
268-
self._instrument_class_temporality[
269-
_ObservableGauge
270-
] = temporality
268+
self._instrument_class_temporality[_ObservableGauge] = (
269+
temporality
270+
)
271271
else:
272272
raise Exception(f"Invalid instrument class found {typ}")
273273

@@ -287,27 +287,27 @@ def __init__(
287287
if typ is Counter:
288288
self._instrument_class_aggregation[_Counter] = aggregation
289289
elif typ is UpDownCounter:
290-
self._instrument_class_aggregation[
291-
_UpDownCounter
292-
] = aggregation
290+
self._instrument_class_aggregation[_UpDownCounter] = (
291+
aggregation
292+
)
293293
elif typ is Histogram:
294-
self._instrument_class_aggregation[
295-
_Histogram
296-
] = aggregation
294+
self._instrument_class_aggregation[_Histogram] = (
295+
aggregation
296+
)
297297
elif typ is Gauge:
298298
self._instrument_class_aggregation[_Gauge] = aggregation
299299
elif typ is ObservableCounter:
300-
self._instrument_class_aggregation[
301-
_ObservableCounter
302-
] = aggregation
300+
self._instrument_class_aggregation[_ObservableCounter] = (
301+
aggregation
302+
)
303303
elif typ is ObservableUpDownCounter:
304304
self._instrument_class_aggregation[
305305
_ObservableUpDownCounter
306306
] = aggregation
307307
elif typ is ObservableGauge:
308-
self._instrument_class_aggregation[
309-
_ObservableGauge
310-
] = aggregation
308+
self._instrument_class_aggregation[_ObservableGauge] = (
309+
aggregation
310+
)
311311
else:
312312
raise Exception(f"Invalid instrument class found {typ}")
313313

@@ -398,13 +398,13 @@ def __init__(
398398
preferred_aggregation=preferred_aggregation,
399399
)
400400
self._lock = RLock()
401-
self._metrics_data: (
402-
"opentelemetry.sdk.metrics.export.MetricsData"
403-
) = None
401+
self._metrics_data: "opentelemetry.sdk.metrics.export.MetricsData" = (
402+
None
403+
)
404404

405405
def get_metrics_data(
406406
self,
407-
) -> ("opentelemetry.sdk.metrics.export.MetricsData"):
407+
) -> "opentelemetry.sdk.metrics.export.MetricsData":
408408
"""Reads and returns current metrics from the SDK"""
409409
with self._lock:
410410
self.collect()
@@ -551,9 +551,7 @@ def _shutdown():
551551

552552
self._shutdown_event.set()
553553
if self._daemon_thread:
554-
self._daemon_thread.join(
555-
timeout=(deadline_ns - time_ns()) / 10**9
556-
)
554+
self._daemon_thread.join(timeout=(deadline_ns - time_ns()) / 10**9)
557555
self._exporter.shutdown(timeout=(deadline_ns - time_ns()) / 10**6)
558556

559557
def force_flush(self, timeout_millis: float = 10_000) -> bool:

opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/metric_reader_storage.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ def _get_or_init_view_instrument_match(
107107
),
108108
)
109109
)
110-
self._instrument_view_instrument_matches[
111-
instrument
112-
] = view_instrument_matches
110+
self._instrument_view_instrument_matches[instrument] = (
111+
view_instrument_matches
112+
)
113113

114114
return view_instrument_matches
115115

@@ -136,9 +136,9 @@ def collect(self) -> Optional[MetricsData]:
136136

137137
with self._lock:
138138

139-
instrumentation_scope_scope_metrics: (
140-
Dict[InstrumentationScope, ScopeMetrics]
141-
) = {}
139+
instrumentation_scope_scope_metrics: Dict[
140+
InstrumentationScope, ScopeMetrics
141+
] = {}
142142

143143
for (
144144
instrument,

0 commit comments

Comments
 (0)