From 94331acf236e697e29b433dc5f4a3417a1b159a4 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 23 Nov 2022 18:49:08 +0100 Subject: [PATCH] Fix lint --- .../src/opentelemetry/context/__init__.py | 11 +++--- .../src/opentelemetry/propagate/__init__.py | 4 +- .../src/opentelemetry/util/_providers.py | 19 ++++------ .../tests/propagators/test_propagators.py | 38 ++++++++----------- opentelemetry-proto/tests/test_proto.py | 2 +- .../sdk/_configuration/__init__.py | 10 ++--- .../opentelemetry/sdk/resources/__init__.py | 1 + .../tests/error_handler/test_error_handler.py | 16 ++++---- opentelemetry-sdk/tests/test_configurator.py | 14 +++---- .../tests/test_semconv.py | 3 +- 10 files changed, 51 insertions(+), 67 deletions(-) diff --git a/opentelemetry-api/src/opentelemetry/context/__init__.py b/opentelemetry-api/src/opentelemetry/context/__init__.py index 0eb32a1207c..ac9f9d7a568 100644 --- a/opentelemetry-api/src/opentelemetry/context/__init__.py +++ b/opentelemetry-api/src/opentelemetry/context/__init__.py @@ -18,7 +18,6 @@ import uuid from functools import wraps from os import environ - from sys import version_info # FIXME remove when support for 3.7 is dropped. @@ -47,7 +46,7 @@ def _load_runtime_context(func: _F) -> _F: @wraps(func) # type: ignore[misc] def wrapper( # type: ignore[misc] *args: typing.Tuple[typing.Any, typing.Any], - **kwargs: typing.Dict[typing.Any, typing.Any] + **kwargs: typing.Dict[typing.Any, typing.Any], ) -> typing.Optional[typing.Any]: global _RUNTIME_CONTEXT # pylint: disable=global-statement @@ -63,9 +62,9 @@ def wrapper( # type: ignore[misc] ) # type: str try: if version_info.minor <= 9: - for entry_point in ( - entry_points()["opentelemetry_context"] - ): + for entry_point in entry_points()[ + "opentelemetry_context" + ]: if entry_point.name == configured_context: _RUNTIME_CONTEXT = entry_point.load()() break @@ -77,7 +76,7 @@ def wrapper( # type: ignore[misc] else: _RUNTIME_CONTEXT = entry_points( group="opentelemetry_context", - name=configured_context + name=configured_context, )[0].load()() except Exception: # pylint: disable=broad-except logger.error( diff --git a/opentelemetry-api/src/opentelemetry/propagate/__init__.py b/opentelemetry-api/src/opentelemetry/propagate/__init__.py index 9392ffca2ee..f350118a8c9 100644 --- a/opentelemetry-api/src/opentelemetry/propagate/__init__.py +++ b/opentelemetry-api/src/opentelemetry/propagate/__init__.py @@ -76,6 +76,7 @@ def example_route(): from opentelemetry.context.context import Context from opentelemetry.environment_variables import OTEL_PROPAGATORS from opentelemetry.propagators import composite, textmap + # FIXME remove when support for 3.7 is dropped. if version_info.minor == 7: from importlib_metadata import entry_points @@ -149,8 +150,7 @@ def inject( propagators.append( entry_points( - group="opentelemetry_propagator", - name=propagator + group="opentelemetry_propagator", name=propagator )[0].load()() ) diff --git a/opentelemetry-api/src/opentelemetry/util/_providers.py b/opentelemetry-api/src/opentelemetry/util/_providers.py index 3dd3046ddb6..c2efbad1ba4 100644 --- a/opentelemetry-api/src/opentelemetry/util/_providers.py +++ b/opentelemetry-api/src/opentelemetry/util/_providers.py @@ -14,8 +14,8 @@ from logging import getLogger from os import environ -from typing import TYPE_CHECKING, TypeVar, cast from sys import version_info +from typing import TYPE_CHECKING, TypeVar, cast # FIXME remove when support for 3.7 is dropped. if version_info.minor == 7: @@ -43,14 +43,11 @@ def _load_provider( provider_name = cast( str, environ.get( - provider_environment_variable, - f"default_{provider}" - ) + provider_environment_variable, f"default_{provider}" + ), ) - for entry_point in ( - entry_points()[f"opentelemetry_{provider}"] - ): + for entry_point in entry_points()[f"opentelemetry_{provider}"]: if entry_point.name == provider_name: return cast(Provider, entry_point.load()()) else: @@ -65,10 +62,10 @@ def _load_provider( str, environ.get( provider_environment_variable, - f"default_{provider}" - ) - ) - )[0].load()() + f"default_{provider}", + ), + ), + )[0].load()(), ) except Exception: # pylint: disable=broad-except logger.exception("Failed to load configured provider %s", provider) diff --git a/opentelemetry-api/tests/propagators/test_propagators.py b/opentelemetry-api/tests/propagators/test_propagators.py index a5971a3c7c6..8e06ce2535c 100644 --- a/opentelemetry-api/tests/propagators/test_propagators.py +++ b/opentelemetry-api/tests/propagators/test_propagators.py @@ -17,9 +17,9 @@ from importlib import reload from logging import ERROR from os import environ +from sys import version_info from unittest import TestCase from unittest.mock import Mock, patch -from sys import version_info from opentelemetry import trace from opentelemetry.baggage.propagation import W3CBaggagePropagator @@ -70,39 +70,28 @@ def test_non_default_propagators( mock_a.configure_mock( **{ "name": "a", - "load.return_value": Mock( - **{"return_value": "a"} - ) + "load.return_value": Mock(**{"return_value": "a"}), } ) mock_b = Mock() mock_b.configure_mock( **{ "name": "b", - "load.return_value": Mock( - **{"return_value": "b"} - ) + "load.return_value": Mock(**{"return_value": "b"}), } ) mock_c = Mock() mock_c.configure_mock( **{ "name": "c", - "load.return_value": Mock( - **{"return_value": "c"} - ) + "load.return_value": Mock(**{"return_value": "c"}), } ) mock_entry_points.configure_mock( **{ "return_value": { - "opentelemetry_propagator": - [ - mock_a, - mock_b, - mock_c - ] + "opentelemetry_propagator": [mock_a, mock_b, mock_c] } } ) @@ -115,27 +104,30 @@ def test_non_default_propagators( [ Mock( **{ - "load.return_value": - Mock(**{"return_value": "a"}) + "load.return_value": Mock( + **{"return_value": "a"} + ) } ), ], [ Mock( **{ - "load.return_value": - Mock(**{"return_value": "b"}) + "load.return_value": Mock( + **{"return_value": "b"} + ) } ) ], [ Mock( **{ - "load.return_value": - Mock(**{"return_value": "c"}) + "load.return_value": Mock( + **{"return_value": "c"} + ) } ) - ] + ], ] } ) diff --git a/opentelemetry-proto/tests/test_proto.py b/opentelemetry-proto/tests/test_proto.py index 2538040b95b..9670be46276 100644 --- a/opentelemetry-proto/tests/test_proto.py +++ b/opentelemetry-proto/tests/test_proto.py @@ -13,8 +13,8 @@ # limitations under the License. # type: ignore -from unittest import TestCase from importlib.util import find_spec +from unittest import TestCase class TestInstrumentor(TestCase): diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py index 97f5dc444bf..80dcd9a7f40 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py @@ -60,6 +60,7 @@ from opentelemetry.sdk.trace.sampling import Sampler from opentelemetry.semconv.resource import ResourceAttributes from opentelemetry.trace import set_tracer_provider + # FIXME remove when support for 3.7 is dropped. if version_info.minor == 7: from importlib_metadata import entry_points @@ -103,9 +104,7 @@ def _import_config_components( if version_info.minor <= 9: - for entry_point in ( - entry_points()[entry_point_name] - ): + for entry_point in entry_points()[entry_point_name]: for selected_component in selected_components: if entry_point.name == selected_component: component_implementations.append( @@ -118,9 +117,8 @@ def _import_config_components( ( selected_component, entry_points( - group=entry_point_name, - name=selected_component - )[0].load() + group=entry_point_name, name=selected_component + )[0].load(), ) ) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py index 4cfce574cfe..32d2b81028e 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py @@ -71,6 +71,7 @@ ) from opentelemetry.semconv.resource import ResourceAttributes from opentelemetry.util.types import AttributeValue + # FIXME remove when support for 3.7 is dropped. if version_info.minor == 7: from importlib_metadata import version diff --git a/opentelemetry-sdk/tests/error_handler/test_error_handler.py b/opentelemetry-sdk/tests/error_handler/test_error_handler.py index 81874626a6d..bdab5095e17 100644 --- a/opentelemetry-sdk/tests/error_handler/test_error_handler.py +++ b/opentelemetry-sdk/tests/error_handler/test_error_handler.py @@ -14,9 +14,9 @@ # pylint: disable=broad-except from logging import ERROR +from sys import version_info from unittest import TestCase from unittest.mock import Mock, patch -from sys import version_info from opentelemetry.sdk.error_handler import ( ErrorHandler, @@ -112,8 +112,9 @@ def _handle(self, error: Exception): mock_entry_points.configure_mock( **{ "return_value": { - "opentelemetry_error_handler": - [mock_entry_point_error_error_handler] + "opentelemetry_error_handler": [ + mock_entry_point_error_error_handler + ] } } ) @@ -132,9 +133,7 @@ def _handle(self, error: Exception): # pylint: disable=no-self-use @patch("opentelemetry.sdk.error_handler.entry_points") - def test_plugin_error_handler_context_manager( - self, mock_entry_points - ): + def test_plugin_error_handler_context_manager(self, mock_entry_points): mock_error_handler_instance = Mock() @@ -152,8 +151,9 @@ def __new__(cls): mock_entry_points.configure_mock( **{ "return_value": { - "opentelemetry_error_handler": - [mock_entry_point_error_handler] + "opentelemetry_error_handler": [ + mock_entry_point_error_handler + ] } } ) diff --git a/opentelemetry-sdk/tests/test_configurator.py b/opentelemetry-sdk/tests/test_configurator.py index 6c5f0653a46..183e5dee064 100644 --- a/opentelemetry-sdk/tests/test_configurator.py +++ b/opentelemetry-sdk/tests/test_configurator.py @@ -16,10 +16,10 @@ import logging from os import environ +from sys import version_info from typing import Dict, Iterable, Optional, Sequence from unittest import TestCase from unittest.mock import patch -from sys import version_info from opentelemetry import trace from opentelemetry.context import Context @@ -411,7 +411,7 @@ def test_trace_init_custom_sampler_with_env(self, mock_entry_points): return_value=[ IterEntryPoint( "custom_sampler_factory", - CustomSamplerFactory.get_custom_sampler + CustomSamplerFactory.get_custom_sampler, ) ] ) @@ -447,7 +447,7 @@ def test_trace_init_custom_sampler_with_env_bad_factory( return_value=[ IterEntryPoint( "custom_sampler_factory", - CustomSamplerFactory.empty_get_custom_sampler + CustomSamplerFactory.empty_get_custom_sampler, ) ] ) @@ -489,7 +489,7 @@ def test_trace_init_custom_sampler_with_env_unused_arg( return_value=[ IterEntryPoint( "custom_sampler_factory", - CustomSamplerFactory.get_custom_sampler + CustomSamplerFactory.get_custom_sampler, ) ] ) @@ -508,9 +508,7 @@ def test_trace_init_custom_sampler_with_env_unused_arg( OTEL_TRACES_SAMPLER_ARG: "0.5", }, ) - def test_trace_init_custom_ratio_sampler_with_env( - self, mock_entry_points - ): + def test_trace_init_custom_ratio_sampler_with_env(self, mock_entry_points): if version_info.minor <= 9: @@ -574,7 +572,7 @@ def test_trace_init_custom_ratio_sampler_with_env_bad_arg( return_value=[ IterEntryPoint( "custom_ratio_sampler_factory", - CustomSamplerFactory.get_custom_ratio_sampler + CustomSamplerFactory.get_custom_ratio_sampler, ) ] ) diff --git a/opentelemetry-semantic-conventions/tests/test_semconv.py b/opentelemetry-semantic-conventions/tests/test_semconv.py index af815dd4e61..a7362a8af77 100644 --- a/opentelemetry-semantic-conventions/tests/test_semconv.py +++ b/opentelemetry-semantic-conventions/tests/test_semconv.py @@ -13,9 +13,8 @@ # limitations under the License. # type: ignore -from unittest import TestCase - from importlib.util import find_spec +from unittest import TestCase class TestSemanticConventions(TestCase):