Skip to content

Commit 7942d8a

Browse files
asottile-sentryandrewshie-sentry
authored andcommitted
ref: run auto-type-annotate on **/issues/**.py (#90000)
first commit automated via https://github.com/getsentry/auto-type-annotate - I used these patches to mypy: - python/mypy#18948 - (the line mentioned in the issue commented out): python/mypy#18940 (comment) - and with this unreverted (coming soon!): #89854 <!-- Describe your PR here. -->
1 parent 35d1388 commit 7942d8a

10 files changed

+95
-58
lines changed

src/sentry/issues/endpoints/group_hashes.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from functools import partial
22

3+
from django.contrib.auth.models import AnonymousUser
34
from rest_framework.request import Request
45
from rest_framework.response import Response
56

@@ -12,6 +13,8 @@
1213
from sentry.models.group import Group
1314
from sentry.models.grouphash import GroupHash
1415
from sentry.tasks.unmerge import unmerge
16+
from sentry.users.models.user import User
17+
from sentry.users.services.user.model import RpcUser
1518
from sentry.utils import metrics
1619
from sentry.utils.snuba import raw_query
1720

@@ -95,12 +98,16 @@ def put(self, request: Request, group: Group) -> Response:
9598

9699
return Response(status=202)
97100

98-
def __handle_results(self, project_id, group_id, user, full, results):
101+
def __handle_results(
102+
self, project_id, group_id, user: User | RpcUser | AnonymousUser | None, full, results
103+
):
99104
return [
100105
self.__handle_result(user, project_id, group_id, full, result) for result in results
101106
]
102107

103-
def __handle_result(self, user, project_id, group_id, full, result):
108+
def __handle_result(
109+
self, user: User | RpcUser | AnonymousUser | None, project_id, group_id, full, result
110+
):
104111
event = eventstore.backend.get_event_by_id(project_id, result["event_id"])
105112

106113
serializer = EventSerializer if full else SimpleEventSerializer

src/sentry/issues/endpoints/organization_issues_count.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from sentry.api.issue_search import convert_query_values, parse_search_query
1414
from sentry.api.utils import get_date_range_from_params
1515
from sentry.exceptions import InvalidParams
16+
from sentry.models.organization import Organization
17+
from sentry.organizations.services.organization.model import RpcOrganization
1618
from sentry.snuba import discover
1719
from sentry.types.ratelimit import RateLimit, RateLimitCategory
1820

@@ -65,7 +67,7 @@ def _count(
6567
result = search.backend.query(**query_kwargs)
6668
return result.hits
6769

68-
def get(self, request: Request, organization) -> Response:
70+
def get(self, request: Request, organization: Organization | RpcOrganization) -> Response:
6971
stats_period = request.GET.get("groupStatsPeriod")
7072
try:
7173
start, end = get_date_range_from_params(request.GET)

tests/sentry/issues/endpoints/test_organization_group_search_view_details_starred.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ class OrganizationGroupSearchViewDetailsStarredEndpointTest(APITestCase):
1010
endpoint = "sentry-api-0-organization-group-search-view-starred"
1111
method = "post"
1212

13-
def setUp(self):
13+
def setUp(self) -> None:
1414
super().setUp()
1515
self.login_as(user=self.user)
1616
self.org = self.create_organization(owner=self.user)
1717

18-
def get_url(self, view_id):
18+
def get_url(self, view_id: int) -> str:
1919
return reverse(
2020
self.endpoint,
2121
kwargs={
@@ -24,7 +24,9 @@ def get_url(self, view_id):
2424
},
2525
)
2626

27-
def create_view(self, user_id=None, visibility=None, starred=False):
27+
def create_view(
28+
self, user_id: int | None = None, visibility: str | None = None, starred: bool = False
29+
) -> GroupSearchView:
2830
user_id = user_id or self.user.id
2931
visibility = visibility or GroupSearchViewVisibility.OWNER
3032

@@ -45,13 +47,13 @@ def create_view(self, user_id=None, visibility=None, starred=False):
4547
return view
4648

4749
@with_feature("organizations:issue-stream-custom-views")
48-
def test_view_not_found(self):
50+
def test_view_not_found(self) -> None:
4951
response = self.client.post(self.get_url(737373), data={"starred": True})
5052

5153
assert response.status_code == 404
5254

5355
@with_feature("organizations:issue-stream-custom-views")
54-
def test_organization_view_accessible(self):
56+
def test_organization_view_accessible(self) -> None:
5557
other_user = self.create_user()
5658
view = self.create_view(
5759
user_id=other_user.id, visibility=GroupSearchViewVisibility.ORGANIZATION
@@ -67,7 +69,7 @@ def test_organization_view_accessible(self):
6769
).exists()
6870

6971
@with_feature("organizations:issue-stream-custom-views")
70-
def test_invalid_request_data(self):
72+
def test_invalid_request_data(self) -> None:
7173
view = self.create_view()
7274

7375
# Missing starred field
@@ -79,7 +81,7 @@ def test_invalid_request_data(self):
7981
assert response.status_code == 400
8082

8183
@with_feature("organizations:issue-stream-custom-views")
82-
def test_star_view_with_position(self):
84+
def test_star_view_with_position(self) -> None:
8385
view1 = self.create_view(starred=True)
8486
view2 = self.create_view(starred=True)
8587
view_to_be_starred = self.create_view()
@@ -111,7 +113,7 @@ def test_star_view_with_position(self):
111113
).exists()
112114

113115
@with_feature("organizations:issue-stream-custom-views")
114-
def test_star_view_without_position(self):
116+
def test_star_view_without_position(self) -> None:
115117
view = self.create_view()
116118

117119
response = self.client.post(self.get_url(view.id), data={"starred": True})
@@ -127,7 +129,7 @@ def test_star_view_without_position(self):
127129
assert starred_view.position == 0
128130

129131
@with_feature("organizations:issue-stream-custom-views")
130-
def test_unstar_view(self):
132+
def test_unstar_view(self) -> None:
131133
starred_view = self.create_view(starred=True)
132134
view_to_be_unstarred = self.create_view(starred=True)
133135

@@ -146,23 +148,23 @@ def test_unstar_view(self):
146148
).exists()
147149

148150
@with_feature("organizations:issue-stream-custom-views")
149-
def test_star_already_starred_view(self):
151+
def test_star_already_starred_view(self) -> None:
150152
view = self.create_view(starred=True)
151153

152154
response = self.client.post(self.get_url(view.id), data={"starred": True})
153155

154156
assert response.status_code == 204
155157

156158
@with_feature("organizations:issue-stream-custom-views")
157-
def test_unstar_not_starred_view(self):
159+
def test_unstar_not_starred_view(self) -> None:
158160
view = self.create_view()
159161

160162
response = self.client.post(self.get_url(view.id), data={"starred": False})
161163

162164
assert response.status_code == 204
163165

164166
@with_feature("organizations:issue-stream-custom-views")
165-
def test_multiple_starred_views_order(self):
167+
def test_multiple_starred_views_order(self) -> None:
166168
view1 = self.create_view()
167169
view2 = self.create_view()
168170
view3 = self.create_view()
@@ -205,7 +207,7 @@ def test_multiple_starred_views_order(self):
205207
)
206208

207209
@with_feature("organizations:issue-stream-custom-views")
208-
def test_unstar_adjust_positions(self):
210+
def test_unstar_adjust_positions(self) -> None:
209211
view1 = self.create_view(starred=True)
210212
view2 = self.create_view(starred=True)
211213
view3 = self.create_view(starred=True)
@@ -233,7 +235,7 @@ def test_unstar_adjust_positions(self):
233235
== 0
234236
)
235237

236-
def test_error_when_feature_flag_disabled(self):
238+
def test_error_when_feature_flag_disabled(self) -> None:
237239
view = self.create_view()
238240

239241
response = self.client.post(self.get_url(view.id), data={"starred": True})

tests/sentry/issues/endpoints/test_organization_group_search_view_starred_order.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class OrganizationGroupSearchViewStarredOrderEndpointTest(APITestCase):
1111
endpoint = "sentry-api-0-organization-group-search-view-starred-order"
1212

13-
def setUp(self):
13+
def setUp(self) -> None:
1414
super().setUp()
1515
self.login_as(user=self.user)
1616
self.user_2 = self.create_user()
@@ -58,7 +58,7 @@ def setUp(self):
5858
visibility=GroupSearchViewVisibility.ORGANIZATION,
5959
)
6060

61-
def star_views(self, view_ids: list[int]):
61+
def star_views(self, view_ids: list[int]) -> None:
6262
for idx, view_id in enumerate(view_ids):
6363
GroupSearchViewStarred.objects.create(
6464
organization=self.organization,
@@ -68,7 +68,7 @@ def star_views(self, view_ids: list[int]):
6868
)
6969

7070
@with_feature("organizations:issue-stream-custom-views")
71-
def test_simple_reordering(self):
71+
def test_simple_reordering(self) -> None:
7272
self.star_views([self.views[0].id, self.views[1].id, self.views[2].id])
7373

7474
new_order = [self.views[2].id, self.views[0].id, self.views[1].id]
@@ -92,7 +92,7 @@ def test_simple_reordering(self):
9292
assert starred_views[2].position == 2
9393

9494
@with_feature("organizations:issue-stream-custom-views")
95-
def test_same_order_reordering(self):
95+
def test_same_order_reordering(self) -> None:
9696
original_order = [self.views[0].id, self.views[1].id, self.views[2].id]
9797

9898
self.star_views(original_order)
@@ -116,7 +116,7 @@ def test_same_order_reordering(self):
116116
assert starred_views[2].position == 2
117117

118118
@with_feature("organizations:issue-stream-custom-views")
119-
def reordering_with_shared_views(self):
119+
def reordering_with_shared_views(self) -> None:
120120
self.star_views([self.views[0].id, self.views[1].id, self.views[2].id, self.shared_view.id])
121121

122122
new_order = [self.shared_view.id, self.views[2].id, self.views[0].id, self.views[1].id]
@@ -143,7 +143,7 @@ def reordering_with_shared_views(self):
143143
assert starred_views[3].position == 3
144144

145145
@with_feature("organizations:issue-stream-custom-views")
146-
def test_empty_starred_list(self):
146+
def test_empty_starred_list(self) -> None:
147147
response = self.client.put(self.url, data={"view_ids": []}, format="json")
148148

149149
assert response.status_code == 204
@@ -154,7 +154,7 @@ def test_empty_starred_list(self):
154154
).exists()
155155

156156
@with_feature("organizations:issue-stream-custom-views")
157-
def test_error_on_fewer_views_than_starred_views(self):
157+
def test_error_on_fewer_views_than_starred_views(self) -> None:
158158
self.star_views([self.views[0].id, self.views[1].id, self.views[2].id])
159159

160160
response = self.client.put(
@@ -164,7 +164,7 @@ def test_error_on_fewer_views_than_starred_views(self):
164164
assert response.status_code == 400
165165

166166
@with_feature("organizations:issue-stream-custom-views")
167-
def test_error_on_more_views_than_starred_views(self):
167+
def test_error_on_more_views_than_starred_views(self) -> None:
168168
self.star_views([self.views[0].id, self.views[1].id])
169169

170170
response = self.client.put(
@@ -176,7 +176,7 @@ def test_error_on_more_views_than_starred_views(self):
176176
assert response.status_code == 400
177177

178178
@with_feature("organizations:issue-stream-custom-views")
179-
def test_error_on_duplicate_view_ids(self):
179+
def test_error_on_duplicate_view_ids(self) -> None:
180180
view_ids = [self.views[0].id, self.views[1].id, self.views[1].id]
181181

182182
response = self.client.put(self.url, data={"view_ids": view_ids}, format="json")
@@ -192,7 +192,7 @@ def test_error_on_duplicate_view_ids(self):
192192
class OrganizationGroupSearchViewStarredOrderTransactionTest(TransactionTestCase):
193193
endpoint = "sentry-api-0-organization-group-search-view-starred-order"
194194

195-
def setUp(self):
195+
def setUp(self) -> None:
196196
super().setUp()
197197
self.login_as(user=self.user)
198198

@@ -209,7 +209,7 @@ def setUp(self):
209209
)
210210

211211
@with_feature("organizations:issue-stream-custom-views")
212-
def test_nonexistent_view_id(self):
212+
def test_nonexistent_view_id(self) -> None:
213213
non_existent_id = 373737
214214
view_ids = [self.view.id, non_existent_id]
215215

tests/sentry/issues/endpoints/test_organization_group_search_views_starred.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def create_view(
4343
)
4444
return view
4545

46-
def star_view(self, user: User, view: GroupSearchView):
46+
def star_view(self, user: User, view: GroupSearchView) -> None:
4747
GroupSearchViewStarred.objects.insert_starred_view(
4848
user_id=user.id,
4949
organization=self.organization,
@@ -52,7 +52,7 @@ def star_view(self, user: User, view: GroupSearchView):
5252

5353
@with_feature({"organizations:issue-stream-custom-views": True})
5454
@with_feature({"organizations:global-views": True})
55-
def test_simple_case(self):
55+
def test_simple_case(self) -> None:
5656
self.login_as(user=self.user)
5757
view_1 = self.create_view(user=self.user, name="Starred View 1", starred=True)
5858
view_2 = self.create_view(user=self.user, name="Starred View 2", starred=True)
@@ -71,7 +71,7 @@ def test_simple_case(self):
7171

7272
@with_feature({"organizations:issue-stream-custom-views": True})
7373
@with_feature({"organizations:global-views": True})
74-
def test_views_starred_by_many_users(self):
74+
def test_views_starred_by_many_users(self) -> None:
7575
user_1 = self.user
7676
user_2 = self.create_user()
7777
self.create_member(user=user_2, organization=self.organization)

tests/sentry/issues/endpoints/test_organization_group_suspect_flags.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
import datetime
22
import time
33
import uuid
4+
from typing import TypedDict
45

56
from sentry.testutils.cases import APITestCase, SnubaTestCase
67

78

9+
class _FlagResult(TypedDict):
10+
flag: str
11+
result: bool
12+
13+
814
class OrganizationGroupSuspectFlagsTestCase(APITestCase, SnubaTestCase):
915
endpoint = "sentry-api-0-organization-group-suspect-flags"
1016

11-
def setUp(self):
17+
def setUp(self) -> None:
1218
super().setUp()
1319
self.login_as(user=self.user)
1420

1521
@property
16-
def features(self):
22+
def features(self) -> dict[str, bool]:
1723
return {"organizations:feature-flag-suspect-flags": True}
1824

19-
def test_get(self):
25+
def test_get(self) -> None:
2026
today = datetime.datetime.now(tz=datetime.UTC) - datetime.timedelta(minutes=5)
2127
group = self.create_group(
2228
first_seen=today - datetime.timedelta(hours=1),
@@ -55,19 +61,26 @@ def test_get(self):
5561
]
5662
}
5763

58-
def test_get_no_flag_access(self):
64+
def test_get_no_flag_access(self) -> None:
5965
"""Does not have feature-flag access."""
6066
group = self.create_group()
6167
response = self.client.get(f"/api/0/issues/{group.id}/suspect/flags/")
6268
assert response.status_code == 404
6369

64-
def test_get_no_group(self):
70+
def test_get_no_group(self) -> None:
6571
"""Group not found."""
6672
with self.feature(self.features):
6773
response = self.client.get("/api/0/issues/22/suspect/flags/")
6874
assert response.status_code == 404
6975

70-
def _mock_event(self, ts, hash="a" * 32, group_id=None, project_id=1, flags=None):
76+
def _mock_event(
77+
self,
78+
ts: datetime.datetime,
79+
hash: str = "a" * 32,
80+
group_id: int | None = None,
81+
project_id: int = 1,
82+
flags: list[_FlagResult] | None = None,
83+
) -> None:
7184
self.snuba_insert(
7285
(
7386
2,

tests/sentry/issues/endpoints/test_organization_group_suspect_tags.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
class OrganizationGroupSuspectTagsTestCase(APITestCase, SnubaTestCase):
99
endpoint = "sentry-api-0-organization-group-suspect-tags"
1010

11-
def setUp(self):
11+
def setUp(self) -> None:
1212
super().setUp()
1313
self.login_as(user=self.user)
1414

1515
@property
16-
def features(self):
16+
def features(self) -> dict[str, bool]:
1717
return {"organizations:issues-suspect-tags": True}
1818

19-
def test_get(self):
19+
def test_get(self) -> None:
2020
today = datetime.datetime.now(tz=datetime.UTC) - datetime.timedelta(minutes=5)
2121
group = self.create_group(
2222
first_seen=today - datetime.timedelta(hours=1),
@@ -49,13 +49,13 @@ def test_get(self):
4949
]
5050
}
5151

52-
def test_get_no_tag_access(self):
52+
def test_get_no_tag_access(self) -> None:
5353
"""Does not have feature-tag access."""
5454
group = self.create_group()
5555
response = self.client.get(f"/api/0/issues/{group.id}/suspect/tags/")
5656
assert response.status_code == 404
5757

58-
def test_get_no_group(self):
58+
def test_get_no_group(self) -> None:
5959
"""Group not found."""
6060
with self.feature(self.features):
6161
response = self.client.get("/api/0/issues/22/suspect/tags/")

0 commit comments

Comments
 (0)