Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Nov 23, 2022
1 parent 3bf6f47 commit 94331ac
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 67 deletions.
11 changes: 5 additions & 6 deletions opentelemetry-api/src/opentelemetry/context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-api/src/opentelemetry/propagate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -149,8 +150,7 @@ def inject(

propagators.append(
entry_points(
group="opentelemetry_propagator",
name=propagator
group="opentelemetry_propagator", name=propagator
)[0].load()()
)

Expand Down
19 changes: 8 additions & 11 deletions opentelemetry-api/src/opentelemetry/util/_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down
38 changes: 15 additions & 23 deletions opentelemetry-api/tests/propagators/test_propagators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
}
}
)
Expand All @@ -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"}
)
}
)
]
],
]
}
)
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-proto/tests/test_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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(),
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions opentelemetry-sdk/tests/error_handler/test_error_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
]
}
}
)
Expand All @@ -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()

Expand All @@ -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
]
}
}
)
Expand Down
14 changes: 6 additions & 8 deletions opentelemetry-sdk/tests/test_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
]
)
Expand Down Expand Up @@ -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,
)
]
)
Expand Down Expand Up @@ -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,
)
]
)
Expand All @@ -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:

Expand Down Expand Up @@ -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,
)
]
)
Expand Down
3 changes: 1 addition & 2 deletions opentelemetry-semantic-conventions/tests/test_semconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 94331ac

Please sign in to comment.