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

Commit 1cf9ab2

Browse files
committed
Improve BaseLoader and other type annotations
With this change, we now have proper types and thus autocompletion for all the XYZLoader.loader() calls.
1 parent f717a2b commit 1cf9ab2

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

graphql_api/dataloader/loader.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
from typing import Self
2+
13
from aiodataloader import DataLoader
24
from asgiref.sync import sync_to_async
5+
from graphql import GraphQLResolveInfo
36

47

58
class BaseLoader(DataLoader):
69
@classmethod
7-
def loader(cls, info, *args):
10+
def loader(cls, info: GraphQLResolveInfo, *args) -> Self:
811
"""
912
Creates a new loader for the given `info` (instance of GraphQLResolveInfo) and `args`.
1013
If a loader of this type already exists for the given `args` then that same object will

graphql_api/types/commit/commit.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,36 +64,36 @@
6464

6565

6666
@commit_bindable.field("author")
67-
def resolve_author(commit, info):
67+
def resolve_author(commit: Commit, info: GraphQLResolveInfo) -> Owner | None:
6868
if commit.author_id:
6969
return OwnerLoader.loader(info).load(commit.author_id)
7070

7171

7272
@commit_bindable.field("parent")
73-
def resolve_parent(commit, info):
73+
def resolve_parent(commit: Commit, info: GraphQLResolveInfo) -> Commit | None:
7474
if commit.parent_commit_id:
7575
return CommitLoader.loader(info, commit.repository_id).load(
7676
commit.parent_commit_id
7777
)
7878

7979

8080
@commit_bindable.field("yaml")
81-
async def resolve_yaml(commit: Commit, info) -> dict:
81+
async def resolve_yaml(commit: Commit, info: GraphQLResolveInfo) -> dict:
8282
command = info.context["executor"].get_command("commit")
8383
final_yaml = await command.get_final_yaml(commit)
8484
return yaml.dump(final_yaml)
8585

8686

8787
@commit_bindable.field("yamlState")
88-
async def resolve_yaml_state(commit: Commit, info) -> YamlStates:
88+
async def resolve_yaml_state(commit: Commit, info: GraphQLResolveInfo) -> YamlStates:
8989
command = info.context["executor"].get_command("commit")
9090
final_yaml = await command.get_final_yaml(commit)
9191
return get_yaml_state(yaml=final_yaml)
9292

9393

9494
@commit_bindable.field("uploads")
9595
@sync_to_async
96-
def resolve_list_uploads(commit: Commit, info, **kwargs):
96+
def resolve_list_uploads(commit: Commit, info: GraphQLResolveInfo, **kwargs):
9797
if not commit.commitreport:
9898
return queryset_to_connection_sync([])
9999

@@ -118,7 +118,9 @@ def resolve_list_uploads(commit: Commit, info, **kwargs):
118118

119119
@commit_bindable.field("compareWithParent")
120120
@sentry_sdk.trace
121-
async def resolve_compare_with_parent(commit: Commit, info, **kwargs):
121+
async def resolve_compare_with_parent(
122+
commit: Commit, info: GraphQLResolveInfo, **kwargs
123+
):
122124
if not commit.parent_commit_id:
123125
return MissingBaseCommit()
124126

graphql_api/types/comparison/comparison.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def resolve_state(comparison: ComparisonReport, info: GraphQLResolveInfo) -> str
3939
@sync_to_async
4040
def resolve_impacted_files(
4141
comparison_report: ComparisonReport, info: GraphQLResolveInfo, filters=None
42-
) -> List[ImpactedFile]:
42+
):
4343
command: CompareCommands = info.context["executor"].get_command("compare")
4444
comparison: Comparison = info.context.get("comparison", None)
4545

@@ -59,23 +59,23 @@ def resolve_impacted_files(
5959
@sync_to_async
6060
def resolve_impacted_files_count(
6161
comparison: ComparisonReport, info: GraphQLResolveInfo
62-
):
62+
) -> int:
6363
return len(comparison.impacted_files)
6464

6565

6666
@comparison_bindable.field("directChangedFilesCount")
6767
@sync_to_async
6868
def resolve_direct_changed_files_count(
6969
comparison: ComparisonReport, info: GraphQLResolveInfo
70-
):
70+
) -> int:
7171
return len(comparison.impacted_files_with_direct_changes)
7272

7373

7474
@comparison_bindable.field("indirectChangedFilesCount")
7575
@sync_to_async
7676
def resolve_indirect_changed_files_count(
7777
comparison: ComparisonReport, info: GraphQLResolveInfo
78-
):
78+
) -> int:
7979
return len(comparison.impacted_files_with_unintended_changes)
8080

8181

@@ -157,10 +157,9 @@ async def resolve_head_totals(
157157

158158

159159
@comparison_bindable.field("patchTotals")
160-
@sentry_sdk.trace
161160
def resolve_patch_totals(
162161
comparison: ComparisonReport, info: GraphQLResolveInfo
163-
) -> dict:
162+
) -> dict | None:
164163
totals = comparison.commit_comparison.patch_totals
165164
if not totals:
166165
return None
@@ -233,7 +232,7 @@ def resolve_component_comparisons_count(
233232
@sync_to_async
234233
def resolve_flag_comparisons_count(
235234
comparison: ComparisonReport, info: GraphQLResolveInfo
236-
):
235+
) -> int:
237236
"""
238237
Resolver to return if the head and base of a pull request have
239238
different number of reports on the head and base. This implementation

0 commit comments

Comments
 (0)