-
Notifications
You must be signed in to change notification settings - Fork 711
Running mypy on sdk resources #773 #4360
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
base: main
Are you sure you want to change the base?
Changes from 2 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 | ||||||
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. I'd rather prefer to use |
||||||
|
||||||
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 | ||||||
""" | ||||||
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 | ||||||
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 | ||||||
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 | ||||||
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 can be typed, https://github.com/python/importlib_metadata/blob/main/importlib_metadata/__init__.py#L1039C42-L1039C43 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. 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. basedpyright: Import "opentelemetry.util._importlib_metadata" could not be resolved. This results in following errors when mypy is executed - opentelemetry-sdk/src/opentelemetry/sdk/error_handler/init.py:119: error: Type of variable becomes "Any" due to an unfollowed import [no-any-unimported] 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. @xrmx Please let me know if the above errors can be handled differently. 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. I mean something like this 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 PR has more type ignores than actual typing improvements. 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 is a tricky one to type hint because of the way https://github.com/open-telemetry/opentelemetry-python/blob/main/opentelemetry-api/src/opentelemetry/util/_importlib_metadata.py is implemented. 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. @Kludex do you have any suggestions? 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 PR is really only adding 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. My suggestion is for the project to fix the mypy setup in this project, or move to pyright. I'm happy to help, if the maintainers are willing. If you can help, please create an issue about the mypy setup. |
||||||
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 | ||||||
error_handler_class = error_handler_entry_point.load() # type: ignore | ||||||
|
||||||
if issubclass(error_handler_class, exc_value.__class__): | ||||||
if issubclass(error_handler_class, exc_value.__class__): # type: ignore | ||||||
try: | ||||||
error_handler_class()._handle(exc_value) | ||||||
error_handler_class()._handle(exc_value) # type: ignore | ||||||
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 | ||||||
error_handler_class.__name__, # type: ignore | ||||||
) | ||||||
|
||||||
if not plugin_handled: | ||||||
_DefaultErrorHandler()._handle(exc_value) | ||||||
_DefaultErrorHandler()._handle(exc_value) # type: ignore | ||||||
|
||||||
return True |
Uh oh!
There was an error while loading. Please reload this page.