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

Commit8fce110

Browse files
chore: add type-hints to gitlab/v4/objects/groups.py
* Add type-hints to gitlab/v4/objects/groups.py * Add return value to share() function as GitLab docs show it returns a value. * Add 'get()' method so that type-checkers will understand that getting a group is of type Group.
1 parent7925c90 commit8fce110

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

‎gitlab/v4/objects/groups.py‎

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
fromtypingimportAny,BinaryIO,cast,Dict,List,Optional,Type,Union
2+
3+
importrequests
4+
5+
importgitlab
16
fromgitlabimportcli
27
fromgitlabimportexceptionsasexc
38
fromgitlabimporttypes
@@ -74,7 +79,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject):
7479

7580
@cli.register_custom_action("Group", ("project_id",))
7681
@exc.on_http_error(exc.GitlabTransferProjectError)
77-
deftransfer_project(self,project_id,**kwargs):
82+
deftransfer_project(self,project_id:int,**kwargs:Any)->None:
7883
"""Transfer a project to this group.
7984
8085
Args:
@@ -90,7 +95,9 @@ def transfer_project(self, project_id, **kwargs):
9095

9196
@cli.register_custom_action("Group", ("scope","search"))
9297
@exc.on_http_error(exc.GitlabSearchError)
93-
defsearch(self,scope,search,**kwargs):
98+
defsearch(
99+
self,scope:str,search:str,**kwargs:Any
100+
)->Union[gitlab.GitlabList,List[Dict[str,Any]]]:
94101
"""Search the group resources matching the provided string.'
95102
96103
Args:
@@ -111,7 +118,9 @@ def search(self, scope, search, **kwargs):
111118

112119
@cli.register_custom_action("Group", ("cn","group_access","provider"))
113120
@exc.on_http_error(exc.GitlabCreateError)
114-
defadd_ldap_group_link(self,cn,group_access,provider,**kwargs):
121+
defadd_ldap_group_link(
122+
self,cn:str,group_access:int,provider:str,**kwargs:Any
123+
)->None:
115124
"""Add an LDAP group link.
116125
117126
Args:
@@ -131,7 +140,9 @@ def add_ldap_group_link(self, cn, group_access, provider, **kwargs):
131140

132141
@cli.register_custom_action("Group", ("cn",), ("provider",))
133142
@exc.on_http_error(exc.GitlabDeleteError)
134-
defdelete_ldap_group_link(self,cn,provider=None,**kwargs):
143+
defdelete_ldap_group_link(
144+
self,cn:str,provider:Optional[str]=None,**kwargs:Any
145+
)->None:
135146
"""Delete an LDAP group link.
136147
137148
Args:
@@ -151,7 +162,7 @@ def delete_ldap_group_link(self, cn, provider=None, **kwargs):
151162

152163
@cli.register_custom_action("Group")
153164
@exc.on_http_error(exc.GitlabCreateError)
154-
defldap_sync(self,**kwargs):
165+
defldap_sync(self,**kwargs:Any)->None:
155166
"""Sync LDAP groups.
156167
157168
Args:
@@ -166,7 +177,13 @@ def ldap_sync(self, **kwargs):
166177

167178
@cli.register_custom_action("Group", ("group_id","group_access"), ("expires_at",))
168179
@exc.on_http_error(exc.GitlabCreateError)
169-
defshare(self,group_id,group_access,expires_at=None,**kwargs):
180+
defshare(
181+
self,
182+
group_id:int,
183+
group_access:int,
184+
expires_at:Optional[str]=None,
185+
**kwargs:Any,
186+
)->Union[Dict[str,Any],requests.Response]:
170187
"""Share the group with a group.
171188
172189
Args:
@@ -184,11 +201,11 @@ def share(self, group_id, group_access, expires_at=None, **kwargs):
184201
"group_access":group_access,
185202
"expires_at":expires_at,
186203
}
187-
self.manager.gitlab.http_post(path,post_data=data,**kwargs)
204+
returnself.manager.gitlab.http_post(path,post_data=data,**kwargs)
188205

189206
@cli.register_custom_action("Group", ("group_id",))
190207
@exc.on_http_error(exc.GitlabDeleteError)
191-
defunshare(self,group_id,**kwargs):
208+
defunshare(self,group_id:int,**kwargs:Any)->None:
192209
"""Delete a shared group link within a group.
193210
194211
Args:
@@ -269,8 +286,18 @@ class GroupManager(CRUDMixin, RESTManager):
269286
)
270287
_types= {"avatar":types.ImageAttribute,"skip_groups":types.ListAttribute}
271288

289+
defget(self,id:Union[str,int],lazy:bool=False,**kwargs:Any)->Group:
290+
returncast(Group,super().get(id=id,lazy=lazy,**kwargs))
291+
272292
@exc.on_http_error(exc.GitlabImportError)
273-
defimport_group(self,file,path,name,parent_id=None,**kwargs):
293+
defimport_group(
294+
self,
295+
file:BinaryIO,
296+
path:str,
297+
name:str,
298+
parent_id:Optional[str]=None,
299+
**kwargs:Any,
300+
)->Union[Dict[str,Any],requests.Response]:
274301
"""Import a group from an archive file.
275302
276303
Args:
@@ -304,7 +331,7 @@ class GroupSubgroup(RESTObject):
304331

305332
classGroupSubgroupManager(ListMixin,RESTManager):
306333
_path="/groups/%(group_id)s/subgroups"
307-
_obj_cls=GroupSubgroup
334+
_obj_cls:Union[Type["GroupDescendantGroup"],Type[GroupSubgroup]]=GroupSubgroup
308335
_from_parent_attrs= {"group_id":"id"}
309336
_list_filters= (
310337
"skip_groups",
@@ -331,4 +358,4 @@ class GroupDescendantGroupManager(GroupSubgroupManager):
331358
"""
332359

333360
_path="/groups/%(group_id)s/descendant_groups"
334-
_obj_cls=GroupDescendantGroup
361+
_obj_cls:Type[GroupDescendantGroup]=GroupDescendantGroup

‎pyproject.toml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ ignore_errors = true
2323

2424
[[tool.mypy.overrides]]# Overrides to negate above patterns
2525
module = [
26+
"gitlab.v4.objects.groups",
2627
"gitlab.v4.objects.projects",
27-
"gitlab.v4.objects.users"
28+
"gitlab.v4.objects.users",
2829
]
2930
ignore_errors =false
3031

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp