Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 7a37718

Browse files
committed
API Improvements: Fix typings for various files pt3
1 parent 063e7c4 commit 7a37718

File tree

9 files changed

+36
-19
lines changed

9 files changed

+36
-19
lines changed

api/public/v2/component/views.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
from typing import Any
2+
13
from drf_spectacular.types import OpenApiTypes
24
from drf_spectacular.utils import OpenApiParameter, extend_schema
35
from rest_framework import viewsets
6+
from rest_framework.request import Request
47
from rest_framework.response import Response
58

69
from api.public.v2.component.serializers import ComponentSerializer
@@ -34,7 +37,7 @@ class ComponentViewSet(viewsets.ViewSet, RepoPropertyMixin):
3437
permission_classes = [RepositoryArtifactPermissions]
3538

3639
@extend_schema(summary="Component list")
37-
def list(self, request, *args, **kwargs):
40+
def list(self, request: Request, *args: Any, **kwargs: Any) -> Response:
3841
"""
3942
Returns a list of components for the specified repository
4043
"""

codecov_auth/commands/owner/interactors/get_uploads_number_per_user.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
from shared.plan.service import PlanService
24
from shared.upload.utils import query_monthly_coverage_measurements
35

@@ -11,7 +13,7 @@
1113

1214
class GetUploadsNumberPerUserInteractor(BaseInteractor):
1315
@sync_to_async
14-
def execute(self, owner: Owner):
16+
def execute(self, owner: Owner) -> Optional[int]:
1517
plan_service = PlanService(current_org=owner)
1618
monthly_limit = plan_service.monthly_uploads_limit
1719
if monthly_limit is not None:

core/signals.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
from typing import Any, Dict, List, Type
2+
from typing import Any, Dict, List, Type, cast
33

44
from django.db.models.signals import post_save
55
from django.dispatch import receiver
@@ -16,7 +16,7 @@ def update_repository(
1616
sender: Type[Repository], instance: Repository, **kwargs: Dict[str, Any]
1717
) -> None:
1818
log.info(f"Signal triggered for repository {instance.repoid}")
19-
created: bool = kwargs["created"]
19+
created: bool = cast(bool, kwargs["created"])
2020
changes: Dict[str, Any] = instance.tracker.changed()
2121
tracked_fields: List[str] = ["name", "upload_token", "activated", "active"]
2222

graphql_api/types/account/account.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
from typing import Any, Coroutine, Optional
2+
13
from ariadne import ObjectType
24
from graphql import GraphQLResolveInfo
35

46
from codecov.db import sync_to_async
5-
from codecov_auth.models import Account, OktaSettings
7+
from codecov_auth.models import Account, OktaSettings, Owner
68
from graphql_api.helpers.ariadne import ariadne_load_local_graphql
79
from graphql_api.helpers.connection import (
810
build_connection_graphql,
@@ -43,9 +45,9 @@ def resolve_activated_user_count(account: Account, info: GraphQLResolveInfo) ->
4345
def resolve_organizations(
4446
account: Account,
4547
info: GraphQLResolveInfo,
46-
ordering_direction=OrderingDirection.ASC,
47-
**kwargs,
48-
):
48+
ordering_direction: Optional[OrderingDirection] = OrderingDirection.ASC,
49+
**kwargs: Any,
50+
) -> Coroutine[Any, Any, Owner]:
4951
return queryset_to_connection(
5052
account.organizations,
5153
ordering=("username",),

services/profiling.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
class CriticalFile:
19-
def __init__(self, name):
19+
def __init__(self, name: str) -> None:
2020
self.name = name
2121

2222

@@ -60,7 +60,7 @@ def summary_data(
6060
return None
6161

6262
def _get_critical_files_from_yaml(
63-
self, profiling_commit: ProfilingCommit = None
63+
self, profiling_commit: Optional[ProfilingCommit] = None
6464
) -> List[str]:
6565
"""
6666
Get a list of files present in the commit report that are also marked as critical in the repo yaml (under profiling.critical_files_paths)
@@ -79,7 +79,12 @@ def _get_critical_files_from_yaml(
7979
"critical_files_paths"
8080
):
8181
return []
82-
commit_sha = self.commit_sha or profiling_commit.commit_sha
82+
83+
if profiling_commit is not None:
84+
commit_sha = profiling_commit.commit_sha
85+
else:
86+
commit_sha = self.commit_sha
87+
8388
commit = Commit.objects.get(commitid=commit_sha)
8489
report = report_service.build_report_from_commit(commit)
8590
if report is None:

services/report.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ def _sessions_with_specific_flags(
2929

3030

3131
def files_in_sessions(commit_report: Report, session_ids: list[int]) -> list[str]:
32-
files, session_ids = [], set(session_ids)
32+
files, session_ids_set = [], set(session_ids)
3333
for file in commit_report:
3434
found = False
3535
for line in file:
3636
if line:
3737
for session in line.sessions:
38-
if session.id in session_ids:
38+
if session.id in session_ids_set:
3939
found = True
4040
break
4141
if found:

upload/throttles.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
from django.conf import settings
44
from django.core.exceptions import ObjectDoesNotExist
55
from django.db.models import Q
6+
from django.http import HttpRequest
67
from rest_framework.exceptions import ValidationError
78
from rest_framework.throttling import BaseThrottle
9+
from rest_framework.views import APIView
810
from shared.plan.service import PlanService
911
from shared.reports.enums import UploadType
1012
from shared.upload.utils import query_monthly_coverage_measurements
@@ -19,7 +21,7 @@
1921

2022

2123
class UploadsPerCommitThrottle(BaseThrottle):
22-
def allow_request(self, request, view):
24+
def allow_request(self, request: HttpRequest, view: APIView) -> bool:
2325
try:
2426
repository = view.get_repo()
2527
commit = view.get_commit(repository)
@@ -44,7 +46,7 @@ def allow_request(self, request, view):
4446

4547

4648
class UploadsPerWindowThrottle(BaseThrottle):
47-
def allow_request(self, request, view):
49+
def allow_request(self, request: HttpRequest, view: APIView) -> bool:
4850
try:
4951
repository = view.get_repo()
5052
commit = view.get_commit(repository)

upload/tokenless/travis.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
from datetime import datetime, timedelta
3+
from typing import Any, Dict
34

45
import requests
56
from requests.exceptions import ConnectionError, HTTPError
@@ -12,7 +13,7 @@
1213

1314

1415
class TokenlessTravisHandler(BaseTokenlessUploadHandler):
15-
def get_build(self):
16+
def get_build(self) -> Dict[str, Any]:
1617
travis_dot_com = False
1718

1819
try:
@@ -88,7 +89,7 @@ def get_build(self):
8889

8990
return build.json()
9091

91-
def verify(self):
92+
def verify(self) -> str:
9293
# find repo in travis.com
9394
job = self.get_build()
9495

upload/views/upload_completion.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import logging
2+
from typing import Any, Callable, Dict
23

4+
from django.http import HttpRequest
35
from rest_framework import status
46
from rest_framework.generics import CreateAPIView
57
from rest_framework.response import Response
@@ -33,10 +35,10 @@ class UploadCompletionView(CreateAPIView, GetterMixin):
3335
RepositoryLegacyTokenAuthentication,
3436
]
3537

36-
def get_exception_handler(self):
38+
def get_exception_handler(self) -> Callable[[Exception, Dict[str, Any]], Response]:
3739
return repo_auth_custom_exception_handler
3840

39-
def post(self, request, *args, **kwargs):
41+
def post(self, request: HttpRequest, *args: Any, **kwargs: Any) -> Response:
4042
inc_counter(
4143
API_UPLOAD_COUNTER,
4244
labels=generate_upload_prometheus_metrics_labels(

0 commit comments

Comments
 (0)