Skip to content

Commit 9b3db93

Browse files
chore: fix type-hints for ProjectCommit methods
Fix the type-hints for the ProjectCommits methods: - diff() - merge_requests() - refs() These methods all return a List[Dict[str, xxx]] This may not be the final fix as possibly these methods should be calling client.http_list(). But this fixes the type-hints to match what the GitLab API documentation says. Closes: #1805
1 parent a349793 commit 9b3db93

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

gitlab/v4/objects/commits.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, cast, Dict, Optional, TYPE_CHECKING, Union
1+
from typing import Any, cast, Dict, List, Optional, TYPE_CHECKING, Union
22

33
import requests
44

@@ -28,7 +28,7 @@ class ProjectCommit(RESTObject):
2828

2929
@cli.register_custom_action("ProjectCommit")
3030
@exc.on_http_error(exc.GitlabGetError)
31-
def diff(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
31+
def diff(self, **kwargs: Any) -> List[Dict[str, Any]]:
3232
"""Generate the commit diff.
3333
3434
Args:
@@ -42,7 +42,10 @@ def diff(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
4242
The changes done in this commit
4343
"""
4444
path = f"{self.manager.path}/{self.get_id()}/diff"
45-
return self.manager.gitlab.http_get(path, **kwargs)
45+
return cast(
46+
List[Dict[str, Any]],
47+
self.manager.gitlab.http_get(path, **kwargs),
48+
)
4649

4750
@cli.register_custom_action("ProjectCommit", ("branch",))
4851
@exc.on_http_error(exc.GitlabCherryPickError)
@@ -63,9 +66,7 @@ def cherry_pick(self, branch: str, **kwargs: Any) -> None:
6366

6467
@cli.register_custom_action("ProjectCommit", optional=("type",))
6568
@exc.on_http_error(exc.GitlabGetError)
66-
def refs(
67-
self, type: str = "all", **kwargs: Any
68-
) -> Union[Dict[str, Any], requests.Response]:
69+
def refs(self, type: str = "all", **kwargs: Any) -> List[Dict[str, str]]:
6970
"""List the references the commit is pushed to.
7071
7172
Args:
@@ -81,11 +82,14 @@ def refs(
8182
"""
8283
path = f"{self.manager.path}/{self.get_id()}/refs"
8384
data = {"type": type}
84-
return self.manager.gitlab.http_get(path, query_data=data, **kwargs)
85+
return cast(
86+
List[Dict[str, str]],
87+
self.manager.gitlab.http_get(path, query_data=data, **kwargs),
88+
)
8589

8690
@cli.register_custom_action("ProjectCommit")
8791
@exc.on_http_error(exc.GitlabGetError)
88-
def merge_requests(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
92+
def merge_requests(self, **kwargs: Any) -> List[Dict[str, Any]]:
8993
"""List the merge requests related to the commit.
9094
9195
Args:
@@ -99,7 +103,10 @@ def merge_requests(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Respon
99103
The merge requests related to the commit.
100104
"""
101105
path = f"{self.manager.path}/{self.get_id()}/merge_requests"
102-
return self.manager.gitlab.http_get(path, **kwargs)
106+
return cast(
107+
List[Dict[str, Any]],
108+
self.manager.gitlab.http_get(path, **kwargs),
109+
)
103110

104111
@cli.register_custom_action("ProjectCommit", ("branch",))
105112
@exc.on_http_error(exc.GitlabRevertError)

0 commit comments

Comments
 (0)