1+ from typing import Any , cast , Dict , Tuple , TYPE_CHECKING , Union
2+
13from gitlab import cli
24from gitlab import exceptions as exc
35from gitlab import types
@@ -65,6 +67,9 @@ class IssueManager(RetrieveMixin, RESTManager):
6567 )
6668 _types = {"iids" : types .ListAttribute , "labels" : types .ListAttribute }
6769
70+ def get (self , id : Union [str , int ], lazy : bool = False , ** kwargs : Any ) -> Issue :
71+ return cast (Issue , super ().get (id = id , lazy = lazy , ** kwargs ))
72+
6873
6974class GroupIssue (RESTObject ):
7075 pass
@@ -116,7 +121,7 @@ class ProjectIssue(
116121
117122 @cli .register_custom_action ("ProjectIssue" , ("to_project_id" ,))
118123 @exc .on_http_error (exc .GitlabUpdateError )
119- def move (self , to_project_id , ** kwargs ) :
124+ def move (self , to_project_id : int , ** kwargs : Any ) -> None :
120125 """Move the issue to another project.
121126
122127 Args:
@@ -130,11 +135,13 @@ def move(self, to_project_id, **kwargs):
130135 path = f"{ self .manager .path } /{ self .get_id ()} /move"
131136 data = {"to_project_id" : to_project_id }
132137 server_data = self .manager .gitlab .http_post (path , post_data = data , ** kwargs )
138+ if TYPE_CHECKING :
139+ assert isinstance (server_data , dict )
133140 self ._update_attrs (server_data )
134141
135142 @cli .register_custom_action ("ProjectIssue" )
136143 @exc .on_http_error (exc .GitlabGetError )
137- def related_merge_requests (self , ** kwargs ) :
144+ def related_merge_requests (self , ** kwargs : Any ) -> Dict [ str , Any ] :
138145 """List merge requests related to the issue.
139146
140147 Args:
@@ -148,11 +155,14 @@ def related_merge_requests(self, **kwargs):
148155 list: The list of merge requests.
149156 """
150157 path = f"{ self .manager .path } /{ self .get_id ()} /related_merge_requests"
151- return self .manager .gitlab .http_get (path , ** kwargs )
158+ result = self .manager .gitlab .http_get (path , ** kwargs )
159+ if TYPE_CHECKING :
160+ assert isinstance (result , dict )
161+ return result
152162
153163 @cli .register_custom_action ("ProjectIssue" )
154164 @exc .on_http_error (exc .GitlabGetError )
155- def closed_by (self , ** kwargs ) :
165+ def closed_by (self , ** kwargs : Any ) -> Dict [ str , Any ] :
156166 """List merge requests that will close the issue when merged.
157167
158168 Args:
@@ -166,7 +176,10 @@ def closed_by(self, **kwargs):
166176 list: The list of merge requests.
167177 """
168178 path = f"{ self .manager .path } /{ self .get_id ()} /closed_by"
169- return self .manager .gitlab .http_get (path , ** kwargs )
179+ result = self .manager .gitlab .http_get (path , ** kwargs )
180+ if TYPE_CHECKING :
181+ assert isinstance (result , dict )
182+ return result
170183
171184
172185class ProjectIssueManager (CRUDMixin , RESTManager ):
@@ -222,6 +235,11 @@ class ProjectIssueManager(CRUDMixin, RESTManager):
222235 )
223236 _types = {"iids" : types .ListAttribute , "labels" : types .ListAttribute }
224237
238+ def get (
239+ self , id : Union [str , int ], lazy : bool = False , ** kwargs : Any
240+ ) -> ProjectIssue :
241+ return cast (ProjectIssue , super ().get (id = id , lazy = lazy , ** kwargs ))
242+
225243
226244class ProjectIssueLink (ObjectDeleteMixin , RESTObject ):
227245 _id_attr = "issue_link_id"
@@ -234,7 +252,11 @@ class ProjectIssueLinkManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
234252 _create_attrs = RequiredOptional (required = ("target_project_id" , "target_issue_iid" ))
235253
236254 @exc .on_http_error (exc .GitlabCreateError )
237- def create (self , data , ** kwargs ):
255+ # NOTE(jlvillal): Signature doesn't match CreateMixin.create() so ignore
256+ # type error
257+ def create ( # type: ignore
258+ self , data : Dict [str , Any ], ** kwargs : Any
259+ ) -> Tuple [RESTObject , RESTObject ]:
238260 """Create a new object.
239261
240262 Args:
@@ -250,7 +272,12 @@ def create(self, data, **kwargs):
250272 GitlabCreateError: If the server cannot perform the request
251273 """
252274 self ._check_missing_create_attrs (data )
275+ if TYPE_CHECKING :
276+ assert self .path is not None
253277 server_data = self .gitlab .http_post (self .path , post_data = data , ** kwargs )
278+ if TYPE_CHECKING :
279+ assert isinstance (server_data , dict )
280+ assert self ._parent is not None
254281 source_issue = ProjectIssue (self ._parent .manager , server_data ["source_issue" ])
255282 target_issue = ProjectIssue (self ._parent .manager , server_data ["target_issue" ])
256283 return source_issue , target_issue
0 commit comments