diff options
author | John L. Villalovos <john@sodarock.com> | 2022-01-05 17:24:20 -0800 |
---|---|---|
committer | John L. Villalovos <john@sodarock.com> | 2022-01-05 17:24:20 -0800 |
commit | 9b3db93520ce1ae7e21be19c5fe1ede312aeb7c2 (patch) | |
tree | 1cef20a2892233d5e93163981672dfe5dab161f8 /gitlab/v4/objects/commits.py | |
parent | a349793307e3a975bb51f864b48e5e9825f70182 (diff) | |
download | gitlab-jlvillal/list_api.tar.gz |
chore: fix type-hints for ProjectCommit methodsjlvillal/list_api
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
Diffstat (limited to 'gitlab/v4/objects/commits.py')
-rw-r--r-- | gitlab/v4/objects/commits.py | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/gitlab/v4/objects/commits.py b/gitlab/v4/objects/commits.py index 30db0de..6671a98 100644 --- a/gitlab/v4/objects/commits.py +++ b/gitlab/v4/objects/commits.py @@ -1,4 +1,4 @@ -from typing import Any, cast, Dict, Optional, TYPE_CHECKING, Union +from typing import Any, cast, Dict, List, Optional, TYPE_CHECKING, Union import requests @@ -28,7 +28,7 @@ class ProjectCommit(RESTObject): @cli.register_custom_action("ProjectCommit") @exc.on_http_error(exc.GitlabGetError) - def diff(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]: + def diff(self, **kwargs: Any) -> List[Dict[str, Any]]: """Generate the commit diff. Args: @@ -42,7 +42,10 @@ class ProjectCommit(RESTObject): The changes done in this commit """ path = f"{self.manager.path}/{self.get_id()}/diff" - return self.manager.gitlab.http_get(path, **kwargs) + return cast( + List[Dict[str, Any]], + self.manager.gitlab.http_get(path, **kwargs), + ) @cli.register_custom_action("ProjectCommit", ("branch",)) @exc.on_http_error(exc.GitlabCherryPickError) @@ -63,9 +66,7 @@ class ProjectCommit(RESTObject): @cli.register_custom_action("ProjectCommit", optional=("type",)) @exc.on_http_error(exc.GitlabGetError) - def refs( - self, type: str = "all", **kwargs: Any - ) -> Union[Dict[str, Any], requests.Response]: + def refs(self, type: str = "all", **kwargs: Any) -> List[Dict[str, str]]: """List the references the commit is pushed to. Args: @@ -81,11 +82,14 @@ class ProjectCommit(RESTObject): """ path = f"{self.manager.path}/{self.get_id()}/refs" data = {"type": type} - return self.manager.gitlab.http_get(path, query_data=data, **kwargs) + return cast( + List[Dict[str, str]], + self.manager.gitlab.http_get(path, query_data=data, **kwargs), + ) @cli.register_custom_action("ProjectCommit") @exc.on_http_error(exc.GitlabGetError) - def merge_requests(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]: + def merge_requests(self, **kwargs: Any) -> List[Dict[str, Any]]: """List the merge requests related to the commit. Args: @@ -99,7 +103,10 @@ class ProjectCommit(RESTObject): The merge requests related to the commit. """ path = f"{self.manager.path}/{self.get_id()}/merge_requests" - return self.manager.gitlab.http_get(path, **kwargs) + return cast( + List[Dict[str, Any]], + self.manager.gitlab.http_get(path, **kwargs), + ) @cli.register_custom_action("ProjectCommit", ("branch",)) @exc.on_http_error(exc.GitlabRevertError) |