Browse Source

ref: add return type annotation for Fixtures.user (#80768)

<!-- Describe your PR here. -->
anthony sottile 3 months ago
parent
commit
a383fbd183

+ 3 - 2
src/sentry/incidents/logic.py

@@ -94,6 +94,7 @@ from sentry.snuba.subscriptions import (
 )
 from sentry.tasks.relay import schedule_invalidate_project_config
 from sentry.types.actor import Actor
+from sentry.users.models.user import User
 from sentry.users.services.user import RpcUser
 from sentry.utils import metrics
 from sentry.utils.audit import create_audit_entry_from_user
@@ -252,7 +253,7 @@ def update_incident_status(
 def create_incident_activity(
     incident: Incident,
     activity_type: IncidentActivityType,
-    user: RpcUser | None = None,
+    user: RpcUser | User | None = None,
     value: str | int | None = None,
     previous_value: str | int | None = None,
     comment: str | None = None,
@@ -671,7 +672,7 @@ def create_alert_rule(
     return alert_rule
 
 
-def snapshot_alert_rule(alert_rule: AlertRule, user: RpcUser | None = None) -> None:
+def snapshot_alert_rule(alert_rule: AlertRule, user: RpcUser | User | None = None) -> None:
     def nullify_id(model: Model) -> None:
         """Set the id field to null.
 

+ 2 - 1
src/sentry/integrations/jira_server/integration.py

@@ -43,6 +43,7 @@ from sentry.shared_integrations.exceptions import (
 )
 from sentry.silo.base import all_silo_function
 from sentry.users.models.identity import Identity
+from sentry.users.models.user import User
 from sentry.users.services.user import RpcUser
 from sentry.users.services.user.service import user_service
 from sentry.utils.hashlib import sha1_text
@@ -714,7 +715,7 @@ class JiraServerIntegration(IssueSyncIntegration):
         return jira_projects
 
     @all_silo_function
-    def get_create_issue_config(self, group: Group | None, user: RpcUser, **kwargs):
+    def get_create_issue_config(self, group: Group | None, user: RpcUser | User, **kwargs):
         """
         We use the `group` to get three things: organization_slug, project
         defaults, and default title and description. In the case where we're

+ 1 - 1
src/sentry/integrations/mixins/issues.py

@@ -200,7 +200,7 @@ class IssueBasicIntegration(IntegrationInstallation, ABC):
         """
         return []
 
-    def store_issue_last_defaults(self, project: Project, user: RpcUser, data):
+    def store_issue_last_defaults(self, project: Project, user: RpcUser | User, data):
         """
         Stores the last used field defaults on a per-project basis. This
         accepts a dict of values that will be filtered to keys returned by

+ 2 - 1
src/sentry/integrations/slack/notifications.py

@@ -19,6 +19,7 @@ from sentry.integrations.types import ExternalProviders
 from sentry.notifications.notifications.base import BaseNotification
 from sentry.notifications.notify import register_notification_provider
 from sentry.types.actor import Actor
+from sentry.users.models.user import User
 from sentry.utils import metrics
 
 logger = logging.getLogger("sentry.notifications")
@@ -46,7 +47,7 @@ class SlackNotifyBasicMixin(NotifyBasicMixin):
 @register_notification_provider(ExternalProviders.SLACK)
 def send_notification_as_slack(
     notification: BaseNotification,
-    recipients: Iterable[Actor],
+    recipients: Iterable[Actor | User],
     shared_context: Mapping[str, Any],
     extra_context_by_actor: Mapping[Actor, Mapping[str, Any]] | None,
 ) -> None:

+ 2 - 1
src/sentry/sentry_apps/external_requests/issue_link_requester.py

@@ -12,6 +12,7 @@ from sentry.http import safe_urlread
 from sentry.models.group import Group
 from sentry.sentry_apps.external_requests.utils import send_and_save_sentry_app_request, validate
 from sentry.sentry_apps.services.app import RpcSentryAppInstallation
+from sentry.users.models.user import User
 from sentry.users.services.user import RpcUser
 from sentry.utils import json
 
@@ -54,7 +55,7 @@ class IssueLinkRequester:
     uri: str
     group: Group
     fields: dict[str, Any]
-    user: RpcUser
+    user: RpcUser | User
     action: str
 
     def run(self) -> dict[str, Any]:

+ 1 - 1
src/sentry/testutils/fixtures.py

@@ -58,7 +58,7 @@ class Fixtures:
         return self.create_project_key(project=self.project)
 
     @cached_property
-    def user(self):
+    def user(self) -> User:
         return self.create_user("admin@localhost", is_superuser=True, is_staff=True)
 
     @cached_property

+ 1 - 1
tests/sentry/api/endpoints/test_project_rules.py

@@ -822,7 +822,7 @@ class CreateProjectRuleTest(ProjectRuleBaseTestCase):
             "interval": "1h",
             "value": 50,
         }
-        actions = [
+        actions: list[dict[str, object]] = [
             {"id": "sentry.rules.actions.notify_event.NotifyEventAction", "uuid": str(uuid4())}
         ]
         self.run_test(

+ 4 - 4
tests/sentry/api/serializers/test_group_tombstone.py

@@ -8,9 +8,9 @@ from sentry.users.services.user.service import user_service
 class GroupTombstoneSerializerTest(TestCase):
     def test_simple(self):
         user = self.create_user("foo@example.com")
-        self.user = user_service.get_many(filter={"user_ids": [user.id]})[0]
+        rpc_user = user_service.get_many(filter={"user_ids": [user.id]})[0]
         self.login_as(user=user)
-        org = self.create_organization(owner=self.user)
+        org = self.create_organization(owner=rpc_user)
         project = self.create_project(organization=org, name="CoolProj")
         group = self.create_group(project=project)
         tombstone = GroupTombstone.objects.create(
@@ -19,13 +19,13 @@ class GroupTombstoneSerializerTest(TestCase):
             message=group.message,
             culprit=group.culprit,
             data=group.data,
-            actor_id=self.user.id,
+            actor_id=rpc_user.id,
             previous_group_id=group.id,
         )
         GroupHash.objects.create(
             project=group.project, hash="x" * 32, group=group, group_tombstone_id=tombstone.id
         )
-        result = serialize(tombstone, self.user)
+        result = serialize(tombstone, rpc_user)
 
         assert result["message"] == group.message
         assert result["culprit"] == group.culprit

+ 2 - 1
tests/sentry/integrations/discord/test_uninstall.py

@@ -13,6 +13,7 @@ from sentry.silo.base import SiloMode
 from sentry.testutils.cases import APITestCase
 from sentry.testutils.factories import Factories
 from sentry.testutils.silo import assume_test_silo_mode, control_silo_test
+from sentry.users.models.user import User
 from sentry.users.services.user.model import RpcUser
 
 GUILD_ID = "guild-id"
@@ -32,7 +33,7 @@ class DiscordUninstallTest(APITestCase):
     def create_discord_integration(
         self,
         organization: Organization,
-        user: RpcUser | None,
+        user: RpcUser | User | None,
         guild_id: str = GUILD_ID,
         **kwargs: Any,
     ):

+ 1 - 1
tests/sentry/integrations/github/test_search.py

@@ -36,7 +36,7 @@ class GithubSearchTest(APITestCase):
         identity = Identity.objects.create(
             idp=self.create_identity_provider(type=self.provider),
             user=self.user,
-            external_id=self.user.id,
+            external_id=str(self.user.id),
             data={"access_token": "123456789"},
         )
         self.integration.add_organization(self.organization, self.user, identity.id)

Some files were not shown because too many files changed in this diff