Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9a2f54c

Browse files
authored
Merge pull request#1678 from python-gitlab/jlvillal/mypy_commits
chore: add type hints for gitlab/v4/objects/commits.py
2 parents0e6fb5e +dc096a2 commit9a2f54c

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

‎gitlab/v4/objects/commits.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
fromtypingimportAny,cast,Dict,Optional,TYPE_CHECKING,Union
2+
3+
importrequests
4+
15
fromgitlabimportcli
26
fromgitlabimportexceptionsasexc
37
fromgitlab.baseimportRequiredOptional,RESTManager,RESTObject
@@ -24,7 +28,7 @@ class ProjectCommit(RESTObject):
2428

2529
@cli.register_custom_action("ProjectCommit")
2630
@exc.on_http_error(exc.GitlabGetError)
27-
defdiff(self,**kwargs):
31+
defdiff(self,**kwargs:Any)->Union[Dict[str,Any],requests.Response]:
2832
"""Generate the commit diff.
2933
3034
Args:
@@ -42,7 +46,7 @@ def diff(self, **kwargs):
4246

4347
@cli.register_custom_action("ProjectCommit", ("branch",))
4448
@exc.on_http_error(exc.GitlabCherryPickError)
45-
defcherry_pick(self,branch,**kwargs):
49+
defcherry_pick(self,branch:str,**kwargs:Any)->None:
4650
"""Cherry-pick a commit into a branch.
4751
4852
Args:
@@ -59,7 +63,9 @@ def cherry_pick(self, branch, **kwargs):
5963

6064
@cli.register_custom_action("ProjectCommit",optional=("type",))
6165
@exc.on_http_error(exc.GitlabGetError)
62-
defrefs(self,type="all",**kwargs):
66+
defrefs(
67+
self,type:str="all",**kwargs:Any
68+
)->Union[Dict[str,Any],requests.Response]:
6369
"""List the references the commit is pushed to.
6470
6571
Args:
@@ -79,7 +85,7 @@ def refs(self, type="all", **kwargs):
7985

8086
@cli.register_custom_action("ProjectCommit")
8187
@exc.on_http_error(exc.GitlabGetError)
82-
defmerge_requests(self,**kwargs):
88+
defmerge_requests(self,**kwargs:Any)->Union[Dict[str,Any],requests.Response]:
8389
"""List the merge requests related to the commit.
8490
8591
Args:
@@ -97,7 +103,9 @@ def merge_requests(self, **kwargs):
97103

98104
@cli.register_custom_action("ProjectCommit", ("branch",))
99105
@exc.on_http_error(exc.GitlabRevertError)
100-
defrevert(self,branch,**kwargs):
106+
defrevert(
107+
self,branch:str,**kwargs:Any
108+
)->Union[Dict[str,Any],requests.Response]:
101109
"""Revert a commit on a given branch.
102110
103111
Args:
@@ -117,7 +125,7 @@ def revert(self, branch, **kwargs):
117125

118126
@cli.register_custom_action("ProjectCommit")
119127
@exc.on_http_error(exc.GitlabGetError)
120-
defsignature(self,**kwargs):
128+
defsignature(self,**kwargs:Any)->Union[Dict[str,Any],requests.Response]:
121129
"""Get the signature of the commit.
122130
123131
Args:
@@ -172,7 +180,9 @@ class ProjectCommitStatusManager(ListMixin, CreateMixin, RESTManager):
172180
)
173181

174182
@exc.on_http_error(exc.GitlabCreateError)
175-
defcreate(self,data,**kwargs):
183+
defcreate(
184+
self,data:Optional[Dict[str,Any]]=None,**kwargs:Any
185+
)->ProjectCommitStatus:
176186
"""Create a new object.
177187
178188
Args:
@@ -193,8 +203,13 @@ def create(self, data, **kwargs):
193203
# they are missing when using only the API
194204
# See #511
195205
base_path="/projects/%(project_id)s/statuses/%(commit_id)s"
196-
if"project_id"indataand"commit_id"indata:
206+
path:Optional[str]
207+
ifdataisnotNoneand"project_id"indataand"commit_id"indata:
197208
path=base_path%data
198209
else:
199210
path=self._compute_path(base_path)
200-
returnCreateMixin.create(self,data,path=path,**kwargs)
211+
ifTYPE_CHECKING:
212+
assertpathisnotNone
213+
returncast(
214+
ProjectCommitStatus,CreateMixin.create(self,data,path=path,**kwargs)
215+
)

‎pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module = [
2727
"gitlab.v4.objects.applications",
2828
"gitlab.v4.objects.broadcast_messages",
2929
"gitlab.v4.objects.deployments",
30+
"gitlab.v4.objects.commits",
3031
"gitlab.v4.objects.groups",
3132
"gitlab.v4.objects.keys",
3233
"gitlab.v4.objects.merge_requests",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp