-
Notifications
You must be signed in to change notification settings - Fork 464
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
feat(typing): Make monitor_config a TypedDict #2931
Changes from all commits
bdf983b
6b1aa29
c9b840d
4f42df3
9b64c85
94db787
c90f335
dceb48b
ed80d37
c8e1eb4
2576f88
4dbf501
514aa47
62b1d2a
646ca9b
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 |
---|---|---|
|
@@ -3,6 +3,11 @@ | |
import sys | ||
import time | ||
|
||
try: | ||
from typing import cast | ||
except ImportError: | ||
cast = lambda _, o: o | ||
|
||
from sentry_sdk.api import continue_trace | ||
from sentry_sdk.consts import OP | ||
from sentry_sdk._compat import reraise | ||
|
@@ -31,7 +36,15 @@ | |
from typing import Union | ||
|
||
from sentry_sdk.tracing import Span | ||
from sentry_sdk._types import EventProcessor, Event, Hint, ExcInfo | ||
from sentry_sdk._types import ( | ||
EventProcessor, | ||
Event, | ||
Hint, | ||
ExcInfo, | ||
MonitorConfig, | ||
MonitorConfigScheduleType, | ||
MonitorConfigScheduleUnit, | ||
) | ||
|
||
F = TypeVar("F", bound=Callable[..., Any]) | ||
|
||
|
@@ -416,7 +429,7 @@ def _get_headers(task): | |
|
||
|
||
def _get_humanized_interval(seconds): | ||
# type: (float) -> Tuple[int, str] | ||
# type: (float) -> Tuple[int, MonitorConfigScheduleUnit] | ||
TIME_UNITS = ( # noqa: N806 | ||
("day", 60 * 60 * 24.0), | ||
("hour", 60 * 60.0), | ||
|
@@ -427,17 +440,17 @@ def _get_humanized_interval(seconds): | |
for unit, divider in TIME_UNITS: | ||
if seconds >= divider: | ||
interval = int(seconds / divider) | ||
return (interval, unit) | ||
return (interval, cast("MonitorConfigScheduleUnit", unit)) | ||
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. mypy is not smart enough to realize that 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. @szokeasaurusrex Do you think 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.
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. Nvm, looks like you handled the compatibility concern by importing as |
||
|
||
return (int(seconds), "second") | ||
|
||
|
||
def _get_monitor_config(celery_schedule, app, monitor_name): | ||
# type: (Any, Celery, str) -> Dict[str, Any] | ||
monitor_config = {} # type: Dict[str, Any] | ||
schedule_type = None # type: Optional[str] | ||
# type: (Any, Celery, str) -> MonitorConfig | ||
monitor_config = {} # type: MonitorConfig | ||
schedule_type = None # type: Optional[MonitorConfigScheduleType] | ||
schedule_value = None # type: Optional[Union[str, int]] | ||
schedule_unit = None # type: Optional[str] | ||
schedule_unit = None # type: Optional[MonitorConfigScheduleUnit] | ||
|
||
if isinstance(celery_schedule, crontab): | ||
schedule_type = "crontab" | ||
|
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.
Second-level precision can still be provided by the user so this needs to be part of the type