Skip to content

Bump black to 24.3.0 #3871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ ignore =
# allow whitespace before ':' (https://github.com/psf/black#slices)
E203

# conflicts with black
E701
E704

exclude =
.bzr
.git
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pylint==3.0.2
flake8==6.1.0
isort==5.12.0
black==22.3.0
black==24.3.0
httpretty==1.1.4
mypy==1.9.0
sphinx==7.1.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ def translate_to_collector(spans: Sequence[ReadableSpan]):
collector_span.parent_span_id = parent_id.to_bytes(8, "big")

if span.context.trace_state is not None:
for (key, value) in span.context.trace_state.items():
for key, value in span.context.trace_state.items():
collector_span.tracestate.entries.add(key=key, value=value)

if span.attributes:
for (key, value) in span.attributes.items():
for key, value in span.attributes.items():
utils.add_proto_attribute_value(
collector_span.attributes, key, value
)
Expand All @@ -150,7 +150,7 @@ def translate_to_collector(spans: Sequence[ReadableSpan]):
)

if event.attributes:
for (key, value) in event.attributes.items():
for key, value in event.attributes.items():
utils.add_proto_attribute_value(
collector_annotation.attributes, key, value
)
Expand Down Expand Up @@ -183,7 +183,7 @@ def translate_to_collector(spans: Sequence[ReadableSpan]):
)

if link.attributes:
for (key, value) in link.attributes.items():
for key, value in link.attributes.items():
utils.add_proto_attribute_value(
collector_span_link.attributes, key, value
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ def collect(self) -> None:
self._target_info = self._create_info_metric(
_TARGET_INFO_NAME, _TARGET_INFO_DESCRIPTION, attributes
)
metric_family_id_metric_family[
_TARGET_INFO_NAME
] = self._target_info
metric_family_id_metric_family[_TARGET_INFO_NAME] = (
self._target_info
)

while self._metrics_datas:
self._translate_to_prometheus(
Expand Down Expand Up @@ -294,13 +294,13 @@ def _translate_to_prometheus(
)

if metric_family_id not in metric_family_id_metric_family:
metric_family_id_metric_family[
metric_family_id
] = CounterMetricFamily(
name=metric_name,
documentation=metric_description,
labels=label_keys,
unit=metric.unit,
metric_family_id_metric_family[metric_family_id] = (
CounterMetricFamily(
name=metric_name,
documentation=metric_description,
labels=label_keys,
unit=metric.unit,
)
)
metric_family_id_metric_family[
metric_family_id
Expand All @@ -318,13 +318,13 @@ def _translate_to_prometheus(
metric_family_id
not in metric_family_id_metric_family.keys()
):
metric_family_id_metric_family[
metric_family_id
] = GaugeMetricFamily(
name=metric_name,
documentation=metric_description,
labels=label_keys,
unit=metric.unit,
metric_family_id_metric_family[metric_family_id] = (
GaugeMetricFamily(
name=metric_name,
documentation=metric_description,
labels=label_keys,
unit=metric.unit,
)
)
metric_family_id_metric_family[
metric_family_id
Expand All @@ -339,13 +339,13 @@ def _translate_to_prometheus(
metric_family_id
not in metric_family_id_metric_family.keys()
):
metric_family_id_metric_family[
metric_family_id
] = HistogramMetricFamily(
name=metric_name,
documentation=metric_description,
labels=label_keys,
unit=metric.unit,
metric_family_id_metric_family[metric_family_id] = (
HistogramMetricFamily(
name=metric_name,
documentation=metric_description,
labels=label_keys,
unit=metric.unit,
)
)
metric_family_id_metric_family[
metric_family_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,13 @@ def test_header_max_entries_skip_invalid_entry(self):
self._extract(
",".join(
[
f"key{index}=value{index}"
if index != 2
else (
f"key{index}="
f"value{'s' * (W3CBaggagePropagator._MAX_PAIR_LENGTH + 1)}"
(
f"key{index}=value{index}"
if index != 2
else (
f"key{index}="
f"value{'s' * (W3CBaggagePropagator._MAX_PAIR_LENGTH + 1)}"
)
)
for index in range(
W3CBaggagePropagator._MAX_PAIRS + 1
Expand All @@ -162,9 +164,11 @@ def test_header_max_entries_skip_invalid_entry(self):
self._extract(
",".join(
[
f"key{index}=value{index}"
if index != 2
else f"key{index}xvalue{index}"
(
f"key{index}=value{index}"
if index != 2
else f"key{index}xvalue{index}"
)
for index in range(
W3CBaggagePropagator._MAX_PAIRS + 1
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,21 @@ def _import_exporters(
metric_exporters = {}
log_exporters = {}

for (exporter_name, exporter_impl,) in _import_config_components(
for (
exporter_name,
exporter_impl,
) in _import_config_components(
trace_exporter_names, "opentelemetry_traces_exporter"
):
if issubclass(exporter_impl, SpanExporter):
trace_exporters[exporter_name] = exporter_impl
else:
raise RuntimeError(f"{exporter_name} is not a trace exporter")

for (exporter_name, exporter_impl,) in _import_config_components(
for (
exporter_name,
exporter_impl,
) in _import_config_components(
metric_exporter_names, "opentelemetry_metrics_exporter"
):
# The metric exporter components may be push MetricExporter or pull exporters which
Expand All @@ -283,7 +289,10 @@ def _import_exporters(
else:
raise RuntimeError(f"{exporter_name} is not a metric exporter")

for (exporter_name, exporter_impl,) in _import_config_components(
for (
exporter_name,
exporter_impl,
) in _import_config_components(
log_exporter_names, "opentelemetry_logs_exporter"
):
if issubclass(exporter_impl, LogExporter):
Expand Down Expand Up @@ -360,9 +369,9 @@ def _initialize_components(auto_instrumentation_version):
auto_resource = {}
# populate version if using auto-instrumentation
if auto_instrumentation_version:
auto_resource[
ResourceAttributes.TELEMETRY_AUTO_VERSION
] = auto_instrumentation_version
auto_resource[ResourceAttributes.TELEMETRY_AUTO_VERSION] = (
auto_instrumentation_version
)
resource = Resource.create(auto_resource)

_init_tracing(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,22 +202,26 @@ def to_json(self, indent=4) -> str:
"body": self.body,
"severity_number": repr(self.severity_number),
"severity_text": self.severity_text,
"attributes": dict(self.attributes)
if bool(self.attributes)
else None,
"attributes": (
dict(self.attributes) if bool(self.attributes) else None
),
"dropped_attributes": self.dropped_attributes,
"timestamp": ns_to_iso_str(self.timestamp),
"observed_timestamp": ns_to_iso_str(self.observed_timestamp),
"trace_id": f"0x{format_trace_id(self.trace_id)}"
if self.trace_id is not None
else "",
"span_id": f"0x{format_span_id(self.span_id)}"
if self.span_id is not None
else "",
"trace_id": (
f"0x{format_trace_id(self.trace_id)}"
if self.trace_id is not None
else ""
),
"span_id": (
f"0x{format_span_id(self.span_id)}"
if self.span_id is not None
else ""
),
"trace_flags": self.trace_flags,
"resource": repr(self.resource.attributes)
if self.resource
else "",
"resource": (
repr(self.resource.attributes) if self.resource else ""
),
},
indent=indent,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,27 +247,27 @@ def __init__(
if typ is Counter:
self._instrument_class_temporality[_Counter] = temporality
elif typ is UpDownCounter:
self._instrument_class_temporality[
_UpDownCounter
] = temporality
self._instrument_class_temporality[_UpDownCounter] = (
temporality
)
elif typ is Histogram:
self._instrument_class_temporality[
_Histogram
] = temporality
self._instrument_class_temporality[_Histogram] = (
temporality
)
elif typ is Gauge:
self._instrument_class_temporality[_Gauge] = temporality
elif typ is ObservableCounter:
self._instrument_class_temporality[
_ObservableCounter
] = temporality
self._instrument_class_temporality[_ObservableCounter] = (
temporality
)
elif typ is ObservableUpDownCounter:
self._instrument_class_temporality[
_ObservableUpDownCounter
] = temporality
elif typ is ObservableGauge:
self._instrument_class_temporality[
_ObservableGauge
] = temporality
self._instrument_class_temporality[_ObservableGauge] = (
temporality
)
else:
raise Exception(f"Invalid instrument class found {typ}")

Expand All @@ -287,27 +287,27 @@ def __init__(
if typ is Counter:
self._instrument_class_aggregation[_Counter] = aggregation
elif typ is UpDownCounter:
self._instrument_class_aggregation[
_UpDownCounter
] = aggregation
self._instrument_class_aggregation[_UpDownCounter] = (
aggregation
)
elif typ is Histogram:
self._instrument_class_aggregation[
_Histogram
] = aggregation
self._instrument_class_aggregation[_Histogram] = (
aggregation
)
elif typ is Gauge:
self._instrument_class_aggregation[_Gauge] = aggregation
elif typ is ObservableCounter:
self._instrument_class_aggregation[
_ObservableCounter
] = aggregation
self._instrument_class_aggregation[_ObservableCounter] = (
aggregation
)
elif typ is ObservableUpDownCounter:
self._instrument_class_aggregation[
_ObservableUpDownCounter
] = aggregation
elif typ is ObservableGauge:
self._instrument_class_aggregation[
_ObservableGauge
] = aggregation
self._instrument_class_aggregation[_ObservableGauge] = (
aggregation
)
else:
raise Exception(f"Invalid instrument class found {typ}")

Expand Down Expand Up @@ -398,13 +398,13 @@ def __init__(
preferred_aggregation=preferred_aggregation,
)
self._lock = RLock()
self._metrics_data: (
"opentelemetry.sdk.metrics.export.MetricsData"
) = None
self._metrics_data: "opentelemetry.sdk.metrics.export.MetricsData" = (
None
)

def get_metrics_data(
self,
) -> ("opentelemetry.sdk.metrics.export.MetricsData"):
) -> "opentelemetry.sdk.metrics.export.MetricsData":
"""Reads and returns current metrics from the SDK"""
with self._lock:
self.collect()
Expand Down Expand Up @@ -551,9 +551,7 @@ def _shutdown():

self._shutdown_event.set()
if self._daemon_thread:
self._daemon_thread.join(
timeout=(deadline_ns - time_ns()) / 10**9
)
self._daemon_thread.join(timeout=(deadline_ns - time_ns()) / 10**9)
self._exporter.shutdown(timeout=(deadline_ns - time_ns()) / 10**6)

def force_flush(self, timeout_millis: float = 10_000) -> bool:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ def _get_or_init_view_instrument_match(
),
)
)
self._instrument_view_instrument_matches[
instrument
] = view_instrument_matches
self._instrument_view_instrument_matches[instrument] = (
view_instrument_matches
)

return view_instrument_matches

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

with self._lock:

instrumentation_scope_scope_metrics: (
Dict[InstrumentationScope, ScopeMetrics]
) = {}
instrumentation_scope_scope_metrics: Dict[
InstrumentationScope, ScopeMetrics
] = {}

for (
instrument,
Expand Down
Loading