Skip to content

Commit 3ab4dc7

Browse files
Running mypy on sdk resources #773
1 parent 35337ce commit 3ab4dc7

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def _handle(self, error: Exception, *args, **kwargs):
6161

6262
from abc import ABC, abstractmethod
6363
from logging import getLogger
64+
from typing import Optional
6465

6566
from opentelemetry.util._importlib_metadata import entry_points
6667

@@ -69,7 +70,7 @@ def _handle(self, error: Exception, *args, **kwargs):
6970

7071
class ErrorHandler(ABC):
7172
@abstractmethod
72-
def _handle(self, error: Exception, *args, **kwargs):
73+
def _handle(self, error: Exception, *args, **kwargs) -> None: # type: ignore
7374
"""
7475
Handle an exception
7576
"""
@@ -83,7 +84,7 @@ class _DefaultErrorHandler(ErrorHandler):
8384
"""
8485

8586
# pylint: disable=useless-return
86-
def _handle(self, error: Exception, *args, **kwargs):
87+
def _handle(self, error: Exception, *args, **kwargs) -> None: # type: ignore
8788
logger.exception("Error handled by default error handler: ")
8889
return None
8990

@@ -105,26 +106,26 @@ def __new__(cls) -> "GlobalErrorHandler":
105106

106107
return cls._instance
107108

108-
def __enter__(self):
109+
def __enter__(self) -> None:
109110
pass
110111

111112
# pylint: disable=no-self-use
112-
def __exit__(self, exc_type, exc_value, traceback):
113-
if exc_value is None:
113+
def __exit__(self, exc_type, exc_value, traceback) -> Optional[bool]: # type: ignore
114+
if exc_value is None: # type: ignore
114115
return None
115116

116117
plugin_handled = False
117118

118-
error_handler_entry_points = entry_points(
119+
error_handler_entry_points = entry_points( # type: ignore
119120
group="opentelemetry_error_handler"
120121
)
121122

122-
for error_handler_entry_point in error_handler_entry_points:
123-
error_handler_class = error_handler_entry_point.load()
123+
for error_handler_entry_point in error_handler_entry_points: # type: ignore
124+
error_handler_class = error_handler_entry_point.load() # type: ignore
124125

125-
if issubclass(error_handler_class, exc_value.__class__):
126+
if issubclass(error_handler_class, exc_value.__class__): # type: ignore
126127
try:
127-
error_handler_class()._handle(exc_value)
128+
error_handler_class()._handle(exc_value) # type: ignore
128129
plugin_handled = True
129130

130131
# pylint: disable=broad-exception-caught
@@ -133,11 +134,11 @@ def __exit__(self, exc_type, exc_value, traceback):
133134
"%s error while handling error"
134135
" %s by error handler %s",
135136
error_handling_error.__class__.__name__,
136-
exc_value.__class__.__name__,
137-
error_handler_class.__name__,
137+
exc_value.__class__.__name__, # type: ignore
138+
error_handler_class.__name__, # type: ignore
138139
)
139140

140141
if not plugin_handled:
141-
_DefaultErrorHandler()._handle(exc_value)
142+
_DefaultErrorHandler()._handle(exc_value) # type: ignore
142143

143144
return True

opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/exemplar/exemplar_reservoir.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def collect(self, point_attributes: Attributes) -> Optional[Exemplar]:
129129
{
130130
k: v
131131
for k, v in self.__attributes.items()
132-
if k not in point_attributes
132+
if k not in point_attributes # type: ignore
133133
}
134134
if self.__attributes
135135
else None
@@ -162,8 +162,8 @@ class BucketIndexError(ValueError):
162162
class FixedSizeExemplarReservoirABC(ExemplarReservoir):
163163
"""Abstract class for a reservoir with fixed size."""
164164

165-
def __init__(self, size: int, **kwargs) -> None:
166-
super().__init__(**kwargs)
165+
def __init__(self, size: int, **kwargs) -> None: # type: ignore
166+
super().__init__(**kwargs) # type: ignore
167167
self._size: int = size
168168
self._reservoir_storage: Mapping[int, ExemplarBucket] = defaultdict(
169169
ExemplarBucket
@@ -184,7 +184,7 @@ def collect(self, point_attributes: Attributes) -> List[Exemplar]:
184184
exemplars = [
185185
e
186186
for e in (
187-
bucket.collect(point_attributes)
187+
bucket.collect(point_attributes) # type: ignore
188188
for _, bucket in sorted(self._reservoir_storage.items())
189189
)
190190
if e is not None
@@ -257,8 +257,8 @@ class SimpleFixedSizeExemplarReservoir(FixedSizeExemplarReservoirABC):
257257
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#simplefixedsizeexemplarreservoir
258258
"""
259259

260-
def __init__(self, size: int = 1, **kwargs) -> None:
261-
super().__init__(size, **kwargs)
260+
def __init__(self, size: int = 1, **kwargs) -> None: # type: ignore
261+
super().__init__(size, **kwargs) # type: ignore
262262
self._measurements_seen: int = 0
263263

264264
def _reset(self) -> None:
@@ -292,8 +292,8 @@ class AlignedHistogramBucketExemplarReservoir(FixedSizeExemplarReservoirABC):
292292
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#alignedhistogrambucketexemplarreservoir
293293
"""
294294

295-
def __init__(self, boundaries: Sequence[float], **kwargs) -> None:
296-
super().__init__(len(boundaries) + 1, **kwargs)
295+
def __init__(self, boundaries: Sequence[float], **kwargs) -> None: # type: ignore
296+
super().__init__(len(boundaries) + 1, **kwargs) # type: ignore
297297
self._boundaries: Sequence[float] = boundaries
298298

299299
def offer(

0 commit comments

Comments
 (0)