Skip to content

Commit c1fd5c9

Browse files
asottile-sentryChristinarlong
authored andcommitted
ref: unify signature of notify(...) (#74903)
mypy 1.11 noticed these were incompatible <!-- Describe your PR here. -->
1 parent 4078cbe commit c1fd5c9

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

src/sentry/plugins/bases/notify.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
from sentry.integrations.types import ExternalProviders
1111
from sentry.notifications.services.service import notifications_service
1212
from sentry.notifications.types import NotificationSettingEnum
13-
from sentry.plugins.base import Notification, Plugin
13+
from sentry.plugins.base import Plugin
1414
from sentry.plugins.base.configuration import react_plugin_config
15+
from sentry.plugins.base.structs import Notification
1516
from sentry.shared_integrations.exceptions import ApiError
1617
from sentry.types.actor import Actor, ActorType
1718

@@ -51,7 +52,7 @@ def configure(self, project, request):
5152
def get_plugin_type(self):
5253
return "notification"
5354

54-
def notify(self, notification, raise_exception=False):
55+
def notify(self, notification: Notification, raise_exception: bool = False) -> None:
5556
"""
5657
This calls the notify_users method of the plugin.
5758
Normally this method eats the error and logs it but if we
@@ -60,7 +61,7 @@ def notify(self, notification, raise_exception=False):
6061
"""
6162
event = notification.event
6263
try:
63-
return self.notify_users(
64+
self.notify_users(
6465
event.group, event, triggering_rules=[r.label for r in notification.rules]
6566
)
6667
except (
@@ -82,7 +83,6 @@ def notify(self, notification, raise_exception=False):
8283
)
8384
if raise_exception:
8485
raise
85-
return False
8686

8787
def rule_notify(self, event, futures):
8888
rules = []
@@ -180,16 +180,16 @@ def should_notify(self, group, event):
180180

181181
return True
182182

183-
def test_configuration(self, project):
183+
def test_configuration(self, project) -> None:
184184
from sentry.utils.samples import create_sample_event
185185

186186
event = create_sample_event(project, platform="python")
187187
notification = Notification(event=event)
188-
return self.notify(notification, raise_exception=True)
188+
self.notify(notification, raise_exception=True)
189189

190190
def test_configuration_and_get_test_results(self, project):
191191
try:
192-
test_results = self.test_configuration(project)
192+
self.test_configuration(project)
193193
except Exception as exc:
194194
if isinstance(exc, HTTPError) and hasattr(exc.response, "text"):
195195
test_results = f"{exc}\n{exc.response.text[:256]}"
@@ -202,7 +202,7 @@ def test_configuration_and_get_test_results(self, project):
202202
test_results = (
203203
"There was an internal error with the Plugin, %s" % str(exc)[:256]
204204
)
205-
if not test_results:
205+
else:
206206
test_results = "No errors returned"
207207
return test_results
208208

src/sentry_plugins/pushover/plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from sentry.exceptions import PluginError
22
from sentry.integrations.base import FeatureDescription, IntegrationFeatures
3+
from sentry.plugins.base.structs import Notification
34
from sentry.plugins.bases.notify import NotifyPlugin
45
from sentry_plugins.base import CorePluginMixin
56
from sentry_plugins.utils import get_secret_field_config
@@ -106,7 +107,7 @@ def error_message_from_json(self, data):
106107
return " ".join(errors)
107108
return "unknown error"
108109

109-
def notify(self, notification, **kwargs):
110+
def notify(self, notification: Notification, raise_exception: bool = False) -> None:
110111
event = notification.event
111112
group = event.group
112113
project = group.project

src/sentry_plugins/slack/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from sentry import tagstore
44
from sentry.integrations.base import FeatureDescription, IntegrationFeatures
55
from sentry.integrations.slack.message_builder import LEVEL_TO_COLOR
6-
from sentry.plugins.base import Notification
6+
from sentry.plugins.base.structs import Notification
77
from sentry.plugins.bases import notify
88
from sentry.shared_integrations.exceptions import ApiError
99
from sentry.utils import json

tests/sentry/plugins/bases/test_notify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_notify_failure(self):
5656
notification = Notification(event)
5757

5858
with mock.patch.object(DummyNotificationPlugin, "notify_users", side_effect=err):
59-
assert n.notify(notification) is False
59+
n.notify(notification) # does not raise!
6060

6161
def test_test_configuration_and_get_test_results(self):
6262
errors = (

0 commit comments

Comments
 (0)