Skip to content

Commit

Permalink
ref: fix 'base class ... defined the type as None mypy errors (#56124)
Browse files Browse the repository at this point in the history
<!-- Describe your PR here. -->
  • Loading branch information
asottile-sentry committed Sep 13, 2023
1 parent 00774a3 commit cf29f5e
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 37 deletions.
11 changes: 0 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,10 @@ module = [
"sentry.integrations.bitbucket.installed",
"sentry.integrations.bitbucket.integration",
"sentry.integrations.bitbucket.issues",
"sentry.integrations.bitbucket.repository",
"sentry.integrations.bitbucket.uninstalled",
"sentry.integrations.bitbucket.webhook",
"sentry.integrations.bitbucket_server.client",
"sentry.integrations.bitbucket_server.integration",
"sentry.integrations.bitbucket_server.repository",
"sentry.integrations.bitbucket_server.webhook",
"sentry.integrations.example.integration",
"sentry.integrations.example.repository",
Expand All @@ -443,12 +441,10 @@ module = [
"sentry.integrations.github.webhook",
"sentry.integrations.github_enterprise.client",
"sentry.integrations.github_enterprise.integration",
"sentry.integrations.github_enterprise.repository",
"sentry.integrations.github_enterprise.webhook",
"sentry.integrations.gitlab.client",
"sentry.integrations.gitlab.integration",
"sentry.integrations.gitlab.issues",
"sentry.integrations.gitlab.repository",
"sentry.integrations.gitlab.webhooks",
"sentry.integrations.jira.actions.create_ticket",
"sentry.integrations.jira.actions.form",
Expand Down Expand Up @@ -520,9 +516,6 @@ module = [
"sentry.issues.search",
"sentry.issues.status_change",
"sentry.mail.adapter",
"sentry.mail.forms.assigned_to",
"sentry.mail.forms.member_team",
"sentry.mail.forms.notify_email",
"sentry.mail.notifications",
"sentry.management.commands.makemigrations",
"sentry.management.commands.send_fake_data",
Expand Down Expand Up @@ -582,12 +575,8 @@ module = [
"sentry.plugins.endpoints",
"sentry.plugins.helpers",
"sentry.plugins.providers.base",
"sentry.plugins.providers.dummy.repository",
"sentry.plugins.providers.integration_repository",
"sentry.plugins.providers.repository",
"sentry.plugins.sentry_interface_types.models",
"sentry.plugins.sentry_urls.models",
"sentry.plugins.sentry_useragents.models",
"sentry.plugins.sentry_webhooks.plugin",
"sentry.plugins.validators.url",
"sentry.profiles.task",
Expand Down
8 changes: 6 additions & 2 deletions src/sentry/auth/providers/github/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ class GitHubOAuth2Provider(OAuth2Provider):
access_token_url = ACCESS_TOKEN_URL
authorize_url = AUTHORIZE_URL
name = "GitHub"
client_id = CLIENT_ID
client_secret = CLIENT_SECRET

def get_client_id(self):
return CLIENT_ID

def get_client_secret(self):
return CLIENT_SECRET

def __init__(self, org=None, **config):
super().__init__(**config)
Expand Down
8 changes: 4 additions & 4 deletions src/sentry/auth/providers/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ def dispatch(self, request: Request, helper) -> HttpResponse:


class OAuth2Provider(Provider, abc.ABC):
client_id = None
client_secret = None
is_partner = False

@abc.abstractmethod
def get_client_id(self):
return self.client_id
raise NotImplementedError

@abc.abstractmethod
def get_client_secret(self):
return self.client_secret
raise NotImplementedError

def get_auth_pipeline(self):
return [
Expand Down
12 changes: 6 additions & 6 deletions src/sentry/integrations/mixins/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
from collections import defaultdict
from copy import deepcopy
from typing import Any, Mapping, Sequence
from typing import Any, ClassVar, Mapping, Sequence

from sentry.integrations.utils import where_should_sync
from sentry.models import ExternalIssue, GroupLink, UserOption
Expand Down Expand Up @@ -341,11 +341,11 @@ def update_comment(self, issue_id, user_id, group_note):


class IssueSyncMixin(IssueBasicMixin):
comment_key = None
outbound_status_key = None
inbound_status_key = None
outbound_assignee_key = None
inbound_assignee_key = None
comment_key: ClassVar[str | None] = None
outbound_status_key: ClassVar[str | None] = None
inbound_status_key: ClassVar[str | None] = None
outbound_assignee_key: ClassVar[str | None] = None
inbound_assignee_key: ClassVar[str | None] = None

def should_sync(self, attribute: str) -> bool:
key = getattr(self, f"{attribute}_key", None)
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/mail/forms/assigned_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from sentry.notifications.types import ASSIGNEE_CHOICES, AssigneeTargetType


class AssignedToForm(MemberTeamForm):
class AssignedToForm(MemberTeamForm[AssigneeTargetType]):
targetType = forms.ChoiceField(choices=ASSIGNEE_CHOICES)

teamValue = AssigneeTargetType.TEAM
Expand Down
16 changes: 11 additions & 5 deletions src/sentry/mail/forms/member_team.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
from __future__ import annotations

import enum
from typing import Generic, TypeVar

from django import forms

from sentry.models import OrganizationMemberTeam, Project
from sentry.services.hybrid_cloud.user.service import user_service

T = TypeVar("T", bound=enum.Enum)


class MemberTeamForm(forms.Form):
class MemberTeamForm(forms.Form, Generic[T]):
targetType = forms.ChoiceField()
targetIdentifier = forms.CharField(
required=False, help_text="Only required if 'Member' or 'Team' is selected"
)
teamValue = None
memberValue = None
targetTypeEnum = None
teamValue: T
memberValue: T
targetTypeEnum: type[T]

def __init__(self, project, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -32,7 +37,8 @@ def clean_targetIdentifier(self):
return targetIdentifier

def clean(self) -> None:
cleaned_data = super().clean()
super().clean()
cleaned_data = self.cleaned_data
try:
targetType = self.targetTypeEnum(cleaned_data.get("targetType"))
except ValueError:
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/mail/forms/notify_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from sentry.notifications.types import ACTION_CHOICES, ActionTargetType


class NotifyEmailForm(MemberTeamForm):
class NotifyEmailForm(MemberTeamForm[ActionTargetType]):
targetType = forms.ChoiceField(choices=ACTION_CHOICES)

teamValue = ActionTargetType.TEAM
Expand Down
6 changes: 5 additions & 1 deletion src/sentry/plugins/bases/tag.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from __future__ import annotations

from typing import ClassVar

from sentry.constants import MAX_TAG_VALUE_LENGTH
from sentry.plugins.base.v2 import Plugin2


class TagPlugin(Plugin2):
tag = None
tag: ClassVar[str]
project_default_enabled = True

def get_tag_values(self, event, **kwargs):
Expand Down
6 changes: 3 additions & 3 deletions src/sentry/plugins/providers/integration_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging
from datetime import timezone
from typing import Any, MutableMapping
from typing import Any, ClassVar, MutableMapping

from dateutil.parser import parse as parse_date
from rest_framework.request import Request
Expand Down Expand Up @@ -49,8 +49,8 @@ class IntegrationRepositoryProvider:
Does not include plugins.
"""

name = None
repo_provider = None
name: ClassVar[str]
repo_provider: ClassVar[str]

def __init__(self, id):
self.id = id
Expand Down
5 changes: 4 additions & 1 deletion src/sentry/plugins/providers/repository.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from __future__ import annotations

from logging import getLogger
from typing import ClassVar

from django.db import IntegrityError, router, transaction
from django.urls import reverse
Expand All @@ -24,7 +27,7 @@ class RepositoryProvider(ProviderMixin):
Does not include the integrations in the sentry repository.
"""

name = None
name: ClassVar[str]

def __init__(self, id):
self.id = id
Expand Down
5 changes: 4 additions & 1 deletion src/sentry/tagstore/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from __future__ import annotations

import functools
from typing import ClassVar

from sentry.api.serializers import Serializer, register, serialize
from sentry.search.utils import convert_user_tag_to_query
Expand All @@ -7,7 +10,7 @@

@functools.total_ordering
class TagType:
_sort_key = None
_sort_key: ClassVar[str]

def __repr__(self):
return "<{}: {}>".format(
Expand Down
6 changes: 6 additions & 0 deletions tests/sentry/auth/providers/test_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
class DummyOAuth2Provider(OAuth2Provider):
name = "dummy"

def get_client_id(self):
raise NotImplementedError

def get_client_secret(self):
raise NotImplementedError

def get_refresh_token_url(self) -> str:
raise NotImplementedError

Expand Down
5 changes: 4 additions & 1 deletion tests/sentry/release_health/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import time
from unittest import mock

Expand All @@ -6,6 +8,7 @@
from django.utils import timezone

from sentry.models import GroupRelease, Project, ReleaseProjectEnvironment, Repository
from sentry.release_health.release_monitor.base import BaseReleaseMonitorBackend
from sentry.release_health.release_monitor.metrics import MetricReleaseMonitorBackend
from sentry.release_health.release_monitor.sessions import SessionReleaseMonitorBackend
from sentry.release_health.tasks import monitor_release_adoption, process_projects_with_sessions
Expand All @@ -16,7 +19,7 @@


class BaseTestReleaseMonitor:
backend_class = None
backend_class: type[BaseReleaseMonitorBackend]

def setUp(self):
super().setUp()
Expand Down
6 changes: 6 additions & 0 deletions tests/sentry/web/frontend/test_auth_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ class DummyOAuth2Callback(OAuth2Callback):
class DummyOAuth2Provider(OAuth2Provider):
name = "dummy"

def get_client_id(self):
raise NotImplementedError

def get_client_secret(self):
raise NotImplementedError

def get_refresh_token_url(self) -> str:
raise NotImplementedError

Expand Down

0 comments on commit cf29f5e

Please sign in to comment.