Skip to content

Commit 0718288

Browse files
sbdchduntitaker
authored andcommitted
fix: types for logging integration args (getsentry#444)
* fix: types for logging integration args The sdk supports disabling the LoggingIntegration by passing `None` as arguments; however, the current types require ints. This behavior is noted in the docs: https://docs.sentry.io/platforms/python/logging/#options ``` sentry_sdk.init(integrations=[LoggingIntegration(level=None, event_level=None)]) ``` * fix: type for integration's arg ```python integrations = [ LoggingIntegration(level=None, event_level=None) # type: ignore ] sentry_sdk.init(integrations=integrations) ``` here are the type errors from mypy ``` Argument "integrations" to "init" has incompatible type "List[LoggingIntegration]"; expected "List[Integration]" "List" is invariant -- see http://mypy.readthedocs.io/en/latest/common_issues.html#variance Consider using "Sequence" instead, which is covariant ``` * add missing import
1 parent 2c0a2ea commit 0718288

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

sentry_sdk/consts.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import Type
99
from typing import Dict
1010
from typing import Any
11+
from typing import Sequence
1112

1213
from sentry_sdk.transport import Transport
1314
from sentry_sdk.integrations import Integration
@@ -27,7 +28,7 @@ def __init__(
2728
environment=None, # type: Optional[str]
2829
server_name=None, # type: Optional[str]
2930
shutdown_timeout=2, # type: int
30-
integrations=[], # type: List[Integration]
31+
integrations=[], # type: Sequence[Integration]
3132
in_app_include=[], # type: List[str]
3233
in_app_exclude=[], # type: List[str]
3334
default_integrations=True, # type: bool

sentry_sdk/integrations/logging.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from logging import LogRecord
2020
from typing import Any
2121
from typing import Dict
22+
from typing import Optional
2223

2324
DEFAULT_LEVEL = logging.INFO
2425
DEFAULT_EVENT_LEVEL = logging.ERROR
@@ -40,7 +41,7 @@ class LoggingIntegration(Integration):
4041
identifier = "logging"
4142

4243
def __init__(self, level=DEFAULT_LEVEL, event_level=DEFAULT_EVENT_LEVEL):
43-
# type: (int, int) -> None
44+
# type: (Optional[int], Optional[int]) -> None
4445
self._handler = None
4546
self._breadcrumb_handler = None
4647

0 commit comments

Comments
 (0)