Skip to content

Commit dc67683

Browse files
ref: fix typing in IPlugin2 (#51427)
<!-- Describe your PR here. -->
1 parent 3f1576c commit dc67683

File tree

16 files changed

+54
-43
lines changed

16 files changed

+54
-43
lines changed

pyproject.toml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -828,8 +828,6 @@ module = [
828828
"sentry.plugins.base.bindings",
829829
"sentry.plugins.base.notifier",
830830
"sentry.plugins.base.urls",
831-
"sentry.plugins.base.v1",
832-
"sentry.plugins.base.v2",
833831
"sentry.plugins.bases.data_forwarding",
834832
"sentry.plugins.bases.issue",
835833
"sentry.plugins.bases.issue2",
@@ -845,7 +843,6 @@ module = [
845843
"sentry.plugins.sentry_urls.models",
846844
"sentry.plugins.sentry_useragents.models",
847845
"sentry.plugins.sentry_webhooks.plugin",
848-
"sentry.plugins.utils",
849846
"sentry.plugins.validators.url",
850847
"sentry.profiles.task",
851848
"sentry.profiles.utils",
@@ -855,7 +852,6 @@ module = [
855852
"sentry.quotas.redis",
856853
"sentry.ratelimits.utils",
857854
"sentry.receivers.core",
858-
"sentry.receivers.features",
859855
"sentry.receivers.onboarding",
860856
"sentry.receivers.outbox",
861857
"sentry.receivers.outbox.control",
@@ -1181,7 +1177,6 @@ module = [
11811177
"sentry_plugins.heroku.plugin",
11821178
"sentry_plugins.jira.client",
11831179
"sentry_plugins.jira.plugin",
1184-
"sentry_plugins.opsgenie.plugin",
11851180
"sentry_plugins.pivotal.plugin",
11861181
"sentry_plugins.pushover.plugin",
11871182
"sentry_plugins.redmine.forms",
@@ -1542,10 +1537,8 @@ module = [
15421537
"tests.sentry.options.test_store",
15431538
"tests.sentry.ownership.test_grammar",
15441539
"tests.sentry.pipeline.test_pipeline",
1545-
"tests.sentry.plugins.bases.test_issue",
15461540
"tests.sentry.plugins.bases.test_issue2",
15471541
"tests.sentry.plugins.bases.test_notify",
1548-
"tests.sentry.plugins.test_config",
15491542
"tests.sentry.processing.realtime_metrics.test_redis",
15501543
"tests.sentry.profiles.consumers.test_process",
15511544
"tests.sentry.profiles.test_task",
@@ -1554,7 +1547,6 @@ module = [
15541547
"tests.sentry.ratelimits.test_redis",
15551548
"tests.sentry.ratelimits.utils.test_get_rate_limit_value",
15561549
"tests.sentry.ratelimits.utils.test_get_ratelimit_key",
1557-
"tests.sentry.receivers.test_featureadoption",
15581550
"tests.sentry.receivers.test_onboarding",
15591551
"tests.sentry.receivers.test_releases",
15601552
"tests.sentry.relay.test_config",

src/sentry/api/endpoints/group_details.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from sentry.models.groupinbox import get_inbox_details
2929
from sentry.models.groupowner import get_owner_details
3030
from sentry.plugins.base import plugins
31-
from sentry.plugins.bases import IssueTrackingPlugin2
31+
from sentry.plugins.bases.issue2 import IssueTrackingPlugin2
3232
from sentry.services.hybrid_cloud.user.service import user_service
3333
from sentry.types.ratelimit import RateLimit, RateLimitCategory
3434
from sentry.utils import metrics

src/sentry/plugins/base/v1.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
class PluginMount(type):
2828
def __new__(cls, name, bases, attrs):
29-
new_cls = type.__new__(cls, name, bases, attrs)
29+
new_cls: type[IPlugin] = type.__new__(cls, name, bases, attrs) # type: ignore[assignment]
3030
if IPlugin in bases:
3131
return new_cls
3232
if not hasattr(new_cls, "title"):
@@ -65,7 +65,7 @@ class IPlugin(local, PluggableViewMixin, PluginConfigMixin, PluginStatusMixin):
6565
version: str | None = None
6666
author: str | None = None
6767
author_url: str | None = None
68-
resource_links: list[tuple[str, str]] = ()
68+
resource_links: list[tuple[str, str]] = []
6969
feature_descriptions: Sequence[Any] = []
7070

7171
# Configuration specifics
@@ -276,7 +276,7 @@ def get_form_initial(self, project=None):
276276

277277
# The following methods are specific to web requests
278278

279-
def get_title(self) -> str:
279+
def get_title(self) -> str | _StrPromise:
280280
"""
281281
Returns the general title for this plugin.
282282

src/sentry/plugins/base/v2.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
__all__ = ("Plugin2",)
1+
from __future__ import annotations
22

33
import logging
44
from threading import local
5+
from typing import TYPE_CHECKING, Any, Sequence
56

67
from django.http import HttpResponseRedirect
78

@@ -12,15 +13,18 @@
1213
from sentry.plugins.status import PluginStatusMixin
1314
from sentry.utils.hashlib import md5_text
1415

16+
if TYPE_CHECKING:
17+
from django.utils.functional import _StrPromise
18+
1519

1620
class PluginMount(type):
1721
def __new__(cls, name, bases, attrs):
18-
new_cls = type.__new__(cls, name, bases, attrs)
22+
new_cls: type[IPlugin2] = type.__new__(cls, name, bases, attrs) # type: ignore[assignment]
1923
if IPlugin2 in bases:
2024
return new_cls
21-
if new_cls.title is None:
25+
if not hasattr(new_cls, "title"):
2226
new_cls.title = new_cls.__name__
23-
if not new_cls.slug:
27+
if not hasattr(new_cls, "slug"):
2428
new_cls.slug = new_cls.title.replace(" ", "-").lower()
2529
if not hasattr(new_cls, "logger"):
2630
new_cls.logger = logging.getLogger(f"sentry.plugins.{new_cls.slug}")
@@ -46,20 +50,20 @@ class IPlugin2(local, PluginConfigMixin, PluginStatusMixin):
4650
"""
4751

4852
# Generic plugin information
49-
title = None
50-
slug = None
51-
description = None
52-
version = None
53-
author = None
54-
author_url = None
55-
resource_links = ()
56-
feature_descriptions = []
53+
title: str | _StrPromise
54+
slug: str
55+
description: str | None = None
56+
version: str | None = None
57+
author: str | None = None
58+
author_url: str | None = None
59+
resource_links: list[tuple[str, str]] = []
60+
feature_descriptions: Sequence[Any] = []
5761

5862
# Configuration specifics
59-
conf_key = None
60-
conf_title = None
63+
conf_key: str | None = None
64+
conf_title: str | _StrPromise | None = None
6165

62-
project_conf_form = None
66+
project_conf_form: Any = None
6367
project_conf_template = "sentry/plugins/project_configuration.html"
6468

6569
# Global enabled state
@@ -70,7 +74,7 @@ class IPlugin2(local, PluginConfigMixin, PluginStatusMixin):
7074
project_default_enabled = False
7175

7276
# used by queries to determine if the plugin is configured
73-
required_field = None
77+
required_field: str | None = None
7478

7579
def _get_option_key(self, key):
7680
return f"{self.get_conf_key()}:{key}"
@@ -455,3 +459,6 @@ class Plugin2(IPlugin2, metaclass=PluginMount):
455459
"""
456460

457461
__version__ = 2
462+
463+
464+
__all__ = ("Plugin2",)

src/sentry/plugins/bases/issue.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from django import forms
24
from django.conf import settings
35
from django.utils.html import format_html
@@ -26,7 +28,7 @@ class IssueTrackingPlugin(Plugin):
2628
create_issue_template = "sentry/plugins/bases/issue/create_issue.html"
2729
not_configured_template = "sentry/plugins/bases/issue/not_configured.html"
2830
needs_auth_template = "sentry/plugins/bases/issue/needs_auth.html"
29-
auth_provider = None
31+
auth_provider: str | None = None
3032
can_unlink_issues = False
3133
can_link_existing_issues = False
3234

src/sentry/plugins/bases/issue2.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from django.conf import settings
24
from django.conf.urls import url
35
from django.urls import reverse
@@ -35,13 +37,13 @@ def _handle(self, request: Request, group, *args, **kwargs):
3537

3638

3739
class IssueTrackingPlugin2(Plugin):
38-
auth_provider = None
40+
auth_provider: str | None = None
3941

4042
allowed_actions = ("create", "link", "unlink")
4143

4244
# we default this to None to support legacy integrations, but newer style
4345
# should explicitly call out what is stored
44-
issue_fields = None
46+
issue_fields: frozenset[str] | None = None
4547
# issue_fields = frozenset(['id', 'title', 'url'])
4648

4749
def configure(self, project, request):

src/sentry/plugins/providers/base.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
from __future__ import annotations
2+
3+
import logging
4+
15
from django.urls import reverse
26
from rest_framework.response import Response
37

@@ -8,8 +12,8 @@
812

913

1014
class ProviderMixin:
11-
auth_provider = None
12-
logger = None
15+
auth_provider: str | None = None
16+
logger: logging.Logger | None = None
1317

1418
def link_auth(self, user, organization, data):
1519
try:

src/sentry/plugins/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from sentry.integrations import FeatureDescription, IntegrationFeatures
2-
from sentry.plugins.bases import IssueTrackingPlugin2
2+
from sentry.plugins.bases.issue2 import IssueTrackingPlugin2
33

44

55
class TestIssuePlugin2(IssueTrackingPlugin2):

src/sentry/receivers/features.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from sentry import analytics
66
from sentry.adoption import manager
77
from sentry.models import FeatureAdoption, GroupTombstone, Organization
8-
from sentry.plugins.bases import IssueTrackingPlugin, IssueTrackingPlugin2
8+
from sentry.plugins.bases.issue import IssueTrackingPlugin
9+
from sentry.plugins.bases.issue2 import IssueTrackingPlugin2
910
from sentry.plugins.bases.notify import NotificationPlugin
1011
from sentry.receivers.rules import DEFAULT_RULE_DATA, DEFAULT_RULE_LABEL
1112
from sentry.signals import (

src/sentry/receivers/onboarding.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
Project,
1616
)
1717
from sentry.onboarding_tasks import try_mark_onboarding_complete
18-
from sentry.plugins.bases import IssueTrackingPlugin, IssueTrackingPlugin2
18+
from sentry.plugins.bases.issue import IssueTrackingPlugin
19+
from sentry.plugins.bases.issue2 import IssueTrackingPlugin2
1920
from sentry.services.hybrid_cloud.organization import RpcOrganization
2021
from sentry.services.hybrid_cloud.user import RpcUser
2122
from sentry.signals import (

src/sentry_plugins/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import logging
34
import sys
45
from typing import Any, NoReturn
56

@@ -28,7 +29,7 @@ class CorePluginMixin:
2829
]
2930

3031
# HACK(dcramer): work around MRO issue with plugin metaclass
31-
logger = None
32+
logger: logging.Logger | None = None
3233

3334
# TODO(dcramer): The following is a possible "better implementation" of the
3435
# core issue implementation, though it would need a compat layer to push

src/sentry_plugins/twilio/plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def clean(self) -> dict[str, Any] | None:
101101
class TwilioPlugin(CorePluginMixin, NotificationPlugin):
102102
version = sentry.VERSION
103103
description = DESCRIPTION
104-
resource_links = (
104+
resource_links = [
105105
(
106106
"Documentation",
107107
"https://github.com/getsentry/sentry/blob/master/src/sentry_plugins/twilio/Twilio_Instructions.md",
@@ -112,7 +112,7 @@ class TwilioPlugin(CorePluginMixin, NotificationPlugin):
112112
"https://github.com/getsentry/sentry/tree/master/src/sentry_plugins/twilio",
113113
),
114114
("Twilio", "https://www.twilio.com/"),
115-
)
115+
]
116116

117117
slug = "twilio"
118118
title = _("Twilio (SMS)")

tests/sentry/integrations/bitbucket/test_installed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from sentry.integrations.bitbucket.integration import BitbucketIntegrationProvider, scopes
55
from sentry.models import Integration, Project, Repository
66
from sentry.plugins.base import plugins
7-
from sentry.plugins.bases import IssueTrackingPlugin2
7+
from sentry.plugins.bases.issue2 import IssueTrackingPlugin2
88
from sentry.testutils import APITestCase
99

1010

tests/sentry/integrations/github/test_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from sentry.integrations.utils.code_mapping import Repo, RepoTree
1212
from sentry.models import Integration, OrganizationIntegration, Project, Repository
1313
from sentry.plugins.base import plugins
14-
from sentry.plugins.bases import IssueTrackingPlugin2
14+
from sentry.plugins.bases.issue2 import IssueTrackingPlugin2
1515
from sentry.shared_integrations.exceptions import ApiError
1616
from sentry.testutils import IntegrationTestCase
1717
from sentry.testutils.silo import control_silo_test

tests/sentry/plugins/bases/test_issue2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from sentry.models import GroupMeta, User
66
from sentry.plugins.base import plugins
7-
from sentry.plugins.bases import IssueTrackingPlugin2
7+
from sentry.plugins.bases.issue2 import IssueTrackingPlugin2
88
from sentry.testutils import TestCase
99
from sentry.testutils.helpers.datetime import before_now, iso_format
1010
from sentry.testutils.silo import control_silo_test, region_silo_test

tests/sentry/receivers/test_featureadoption.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from django.utils import timezone
22

33
from sentry.models import FeatureAdoption, GroupAssignee, GroupTombstone, Rule
4-
from sentry.plugins.bases import IssueTrackingPlugin2, NotificationPlugin
4+
from sentry.plugins.bases.issue2 import IssueTrackingPlugin2
5+
from sentry.plugins.bases.notify import NotificationPlugin
56
from sentry.receivers.rules import DEFAULT_RULE_DATA
67
from sentry.signals import (
78
advanced_search,

0 commit comments

Comments
 (0)