-
Notifications
You must be signed in to change notification settings - Fork 681
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
Running mypy on sdk resources #773 #4360
base: main
Are you sure you want to change the base?
Changes from all commits
3ab4dc7
c38154e
5c6d89b
fc6c6e5
822e841
192db0c
853c00f
2ddbd55
d42a650
99f1ff4
825c727
ce4c3a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -61,6 +61,7 @@ def _handle(self, error: Exception, *args, **kwargs): | |||||
|
||||||
from abc import ABC, abstractmethod | ||||||
from logging import getLogger | ||||||
from typing import Optional | ||||||
|
||||||
from opentelemetry.util._importlib_metadata import entry_points | ||||||
|
||||||
|
@@ -69,7 +70,7 @@ def _handle(self, error: Exception, *args, **kwargs): | |||||
|
||||||
class ErrorHandler(ABC): | ||||||
@abstractmethod | ||||||
def _handle(self, error: Exception, *args, **kwargs): | ||||||
def _handle(self, error: Exception, *args, **kwargs) -> None: # type: ignore[misc, no-untyped-def] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
Why is the |
||||||
""" | ||||||
Handle an exception | ||||||
""" | ||||||
|
@@ -83,7 +84,7 @@ class _DefaultErrorHandler(ErrorHandler): | |||||
""" | ||||||
|
||||||
# pylint: disable=useless-return | ||||||
def _handle(self, error: Exception, *args, **kwargs): | ||||||
def _handle(self, error: Exception, *args, **kwargs) -> None: # type: ignore[no-untyped-def] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||||||
logger.exception("Error handled by default error handler: ") | ||||||
return None | ||||||
|
||||||
|
@@ -105,26 +106,26 @@ def __new__(cls) -> "GlobalErrorHandler": | |||||
|
||||||
return cls._instance | ||||||
|
||||||
def __enter__(self): | ||||||
def __enter__(self) -> None: | ||||||
pass | ||||||
|
||||||
# pylint: disable=no-self-use | ||||||
def __exit__(self, exc_type, exc_value, traceback): | ||||||
if exc_value is None: | ||||||
def __exit__(self, exc_type, exc_value, traceback) -> Optional[bool]: # type: ignore[no-untyped-def] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use type hints mentioned here: https://stackoverflow.com/a/58808179 And remove the |
||||||
if exc_value is None: # type: ignore | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If above applied, the ignore is not needed.
Suggested change
|
||||||
return None | ||||||
|
||||||
plugin_handled = False | ||||||
|
||||||
error_handler_entry_points = entry_points( | ||||||
error_handler_entry_points = entry_points( # type: ignore[misc] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question applies to the below. |
||||||
group="opentelemetry_error_handler" | ||||||
) | ||||||
|
||||||
for error_handler_entry_point in error_handler_entry_points: | ||||||
error_handler_class = error_handler_entry_point.load() | ||||||
for error_handler_entry_point in error_handler_entry_points: # type: ignore[misc] | ||||||
error_handler_class = error_handler_entry_point.load() # type: ignore[misc] | ||||||
|
||||||
if issubclass(error_handler_class, exc_value.__class__): | ||||||
if issubclass(error_handler_class, exc_value.__class__): # type: ignore[misc] | ||||||
try: | ||||||
error_handler_class()._handle(exc_value) | ||||||
error_handler_class()._handle(exc_value) # type: ignore[misc] | ||||||
plugin_handled = True | ||||||
|
||||||
# pylint: disable=broad-exception-caught | ||||||
|
@@ -133,11 +134,11 @@ def __exit__(self, exc_type, exc_value, traceback): | |||||
"%s error while handling error" | ||||||
" %s by error handler %s", | ||||||
error_handling_error.__class__.__name__, | ||||||
exc_value.__class__.__name__, | ||||||
error_handler_class.__name__, | ||||||
exc_value.__class__.__name__, # type: ignore[misc] | ||||||
error_handler_class.__name__, # type: ignore[misc] | ||||||
) | ||||||
|
||||||
if not plugin_handled: | ||||||
_DefaultErrorHandler()._handle(exc_value) | ||||||
_DefaultErrorHandler()._handle(exc_value) # type: ignore[misc] | ||||||
|
||||||
return True |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,7 +129,7 @@ def collect(self, point_attributes: Attributes) -> Optional[Exemplar]: | |
{ | ||
k: v | ||
for k, v in self.__attributes.items() | ||
if k not in point_attributes | ||
if k not in point_attributes # type: ignore[operator] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems valid. What values |
||
} | ||
if self.__attributes | ||
else None | ||
|
@@ -162,8 +162,8 @@ class BucketIndexError(ValueError): | |
class FixedSizeExemplarReservoirABC(ExemplarReservoir): | ||
"""Abstract class for a reservoir with fixed size.""" | ||
|
||
def __init__(self, size: int, **kwargs) -> None: | ||
super().__init__(**kwargs) | ||
def __init__(self, size: int, **kwargs) -> None: # type: ignore[no-untyped-def] | ||
super().__init__(**kwargs) # type: ignore[misc] | ||
Comment on lines
+165
to
+166
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the signature of |
||
self._size: int = size | ||
self._reservoir_storage: Mapping[int, ExemplarBucket] = defaultdict( | ||
ExemplarBucket | ||
|
@@ -257,8 +257,8 @@ class SimpleFixedSizeExemplarReservoir(FixedSizeExemplarReservoirABC): | |
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#simplefixedsizeexemplarreservoir | ||
""" | ||
|
||
def __init__(self, size: int = 1, **kwargs) -> None: | ||
super().__init__(size, **kwargs) | ||
def __init__(self, size: int = 1, **kwargs) -> None: # type: ignore[no-untyped-def] | ||
super().__init__(size, **kwargs) # type: ignore[misc] | ||
self._measurements_seen: int = 0 | ||
|
||
def _reset(self) -> None: | ||
|
@@ -292,8 +292,8 @@ class AlignedHistogramBucketExemplarReservoir(FixedSizeExemplarReservoirABC): | |
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#alignedhistogrambucketexemplarreservoir | ||
""" | ||
|
||
def __init__(self, boundaries: Sequence[float], **kwargs) -> None: | ||
super().__init__(len(boundaries) + 1, **kwargs) | ||
def __init__(self, boundaries: Sequence[float], **kwargs) -> None: # type: ignore[no-untyped-def] | ||
super().__init__(len(boundaries) + 1, **kwargs) # type: ignore[misc] | ||
self._boundaries: Sequence[float] = boundaries | ||
|
||
def offer( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather prefer to use
from __future__ import annotations
on the top of the imports, and use pipe (|
) annotation.