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

Commit5f23ed9

Browse files
authored
Merge pull request#1342 from JohnVillalovos/jlvillal/mypy_incomplete
chore: disallow incomplete type defs
2 parentsd8b8a0a +907634f commit5f23ed9

File tree

5 files changed

+45
-31
lines changed

5 files changed

+45
-31
lines changed

‎.mypy.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
[mypy]
22
files = gitlab/*.py
3+
4+
# disallow_incomplete_defs: This flag reports an error whenever it encounters a
5+
# partly annotated function definition.
6+
disallow_incomplete_defs = True

‎gitlab/base.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def __getattr__(self, name: str) -> Any:
9898
exceptKeyError:
9999
raiseAttributeError(name)
100100

101-
def__setattr__(self,name:str,value)->None:
101+
def__setattr__(self,name:str,value:Any)->None:
102102
self.__dict__["_updated_attrs"][name]=value
103103

104104
def__str__(self)->str:
@@ -116,12 +116,16 @@ def __repr__(self) -> str:
116116
else:
117117
return"<%s>"%self.__class__.__name__
118118

119-
def__eq__(self,other)->bool:
119+
def__eq__(self,other:object)->bool:
120+
ifnotisinstance(other,RESTObject):
121+
returnNotImplemented
120122
ifself.get_id()andother.get_id():
121123
returnself.get_id()==other.get_id()
122124
returnsuper(RESTObject,self)==other
123125

124-
def__ne__(self,other)->bool:
126+
def__ne__(self,other:object)->bool:
127+
ifnotisinstance(other,RESTObject):
128+
returnNotImplemented
125129
ifself.get_id()andother.get_id():
126130
returnself.get_id()!=other.get_id()
127131
returnsuper(RESTObject,self)!=other
@@ -144,7 +148,7 @@ def _create_managers(self) -> None:
144148
manager=cls(self.manager.gitlab,parent=self)
145149
self.__dict__[attr]=manager
146150

147-
def_update_attrs(self,new_attrs)->None:
151+
def_update_attrs(self,new_attrs:Dict[str,Any])->None:
148152
self.__dict__["_updated_attrs"]= {}
149153
self.__dict__["_attrs"]=new_attrs
150154

‎gitlab/cli.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
importfunctools
2222
importre
2323
importsys
24-
fromtypingimportAny,Callable,Dict,Tuple
24+
fromtypingimportAny,Callable,Dict,Optional,Tuple,Union
2525

2626
importgitlab.config
2727

@@ -32,21 +32,24 @@
3232
# action: (mandatory_args, optional_args, in_obj),
3333
# },
3434
# }
35-
custom_actions:Dict[str,Dict[str,Tuple[Tuple[Any, ...],Tuple[Any, ...],bool]]]= {}
35+
custom_actions:Dict[str,Dict[str,Tuple[Tuple[str, ...],Tuple[str, ...],bool]]]= {}
3636

3737

3838
defregister_custom_action(
39-
cls_names,mandatory:Tuple[Any, ...]=tuple(),optional:Tuple[Any, ...]=tuple()
39+
cls_names:Union[str,Tuple[str, ...]],
40+
mandatory:Tuple[str, ...]=tuple(),
41+
optional:Tuple[str, ...]=tuple(),
4042
)->Callable:
41-
defwrap(f)->Callable:
43+
defwrap(f:Callable)->Callable:
4244
@functools.wraps(f)
4345
defwrapped_f(*args,**kwargs):
4446
returnf(*args,**kwargs)
4547

4648
# in_obj defines whether the method belongs to the obj or the manager
4749
in_obj=True
48-
classes=cls_names
49-
iftype(cls_names)!=tuple:
50+
ifisinstance(cls_names,tuple):
51+
classes=cls_names
52+
else:
5053
classes= (cls_names,)
5154

5255
forcls_nameinclasses:
@@ -65,7 +68,7 @@ def wrapped_f(*args, **kwargs):
6568
returnwrap
6669

6770

68-
defdie(msg:str,e=None)->None:
71+
defdie(msg:str,e:Optional[Exception]=None)->None:
6972
ife:
7073
msg="%s (%s)"% (msg,e)
7174
sys.stderr.write(msg+"\n")
@@ -76,7 +79,7 @@ def what_to_cls(what: str) -> str:
7679
return"".join([s.capitalize()forsinwhat.split("-")])
7780

7881

79-
defcls_to_what(cls)->str:
82+
defcls_to_what(cls:Any)->str:
8083
returncamel_re.sub(r"\1-\2",cls.__name__).lower()
8184

8285

‎gitlab/client.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def __init__(
145145
def__enter__(self)->"Gitlab":
146146
returnself
147147

148-
def__exit__(self,*args)->None:
148+
def__exit__(self,*args:Any)->None:
149149
self.session.close()
150150

151151
def__getstate__(self)->Dict[str,Any]:
@@ -180,7 +180,9 @@ def api_version(self) -> str:
180180
returnself._api_version
181181

182182
@classmethod
183-
deffrom_config(cls,gitlab_id=None,config_files=None)->"Gitlab":
183+
deffrom_config(
184+
cls,gitlab_id:Optional[str]=None,config_files:Optional[List[str]]=None
185+
)->"Gitlab":
184186
"""Create a Gitlab connection from configuration files.
185187
186188
Args:
@@ -247,7 +249,7 @@ def version(self) -> Tuple[str, str]:
247249
returncast(str,self._server_version),cast(str,self._server_revision)
248250

249251
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabVerifyError)
250-
deflint(self,content:str,**kwargs)->Tuple[bool,List[str]]:
252+
deflint(self,content:str,**kwargs:Any)->Tuple[bool,List[str]]:
251253
"""Validate a gitlab CI configuration.
252254
253255
Args:
@@ -269,7 +271,7 @@ def lint(self, content: str, **kwargs) -> Tuple[bool, List[str]]:
269271

270272
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabMarkdownError)
271273
defmarkdown(
272-
self,text:str,gfm:bool=False,project:Optional[str]=None,**kwargs
274+
self,text:str,gfm:bool=False,project:Optional[str]=None,**kwargs:Any
273275
)->str:
274276
"""Render an arbitrary Markdown document.
275277
@@ -296,7 +298,7 @@ def markdown(
296298
returndata["html"]
297299

298300
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabLicenseError)
299-
defget_license(self,**kwargs)->Dict[str,Any]:
301+
defget_license(self,**kwargs:Any)->Dict[str,Any]:
300302
"""Retrieve information about the current license.
301303
302304
Args:
@@ -315,7 +317,7 @@ def get_license(self, **kwargs) -> Dict[str, Any]:
315317
return {}
316318

317319
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabLicenseError)
318-
defset_license(self,license:str,**kwargs)->Dict[str,Any]:
320+
defset_license(self,license:str,**kwargs:Any)->Dict[str,Any]:
319321
"""Add a new license.
320322
321323
Args:
@@ -446,7 +448,7 @@ def http_request(
446448
post_data:Optional[Dict[str,Any]]=None,
447449
streamed:bool=False,
448450
files:Optional[Dict[str,Any]]=None,
449-
**kwargs,
451+
**kwargs:Any,
450452
)->requests.Response:
451453
"""Make an HTTP request to the Gitlab server.
452454
@@ -577,7 +579,7 @@ def http_get(
577579
query_data:Optional[Dict[str,Any]]=None,
578580
streamed:bool=False,
579581
raw:bool=False,
580-
**kwargs,
582+
**kwargs:Any,
581583
)->Union[Dict[str,Any],requests.Response]:
582584
"""Make a GET request to the Gitlab server.
583585
@@ -621,8 +623,8 @@ def http_list(
621623
self,
622624
path:str,
623625
query_data:Optional[Dict[str,Any]]=None,
624-
as_list=None,
625-
**kwargs,
626+
as_list:Optional[bool]=None,
627+
**kwargs:Any,
626628
)->Union["GitlabList",List[Dict[str,Any]]]:
627629
"""Make a GET request to the Gitlab server for list-oriented queries.
628630
@@ -670,7 +672,7 @@ def http_post(
670672
query_data:Optional[Dict[str,Any]]=None,
671673
post_data:Optional[Dict[str,Any]]=None,
672674
files:Optional[Dict[str,Any]]=None,
673-
**kwargs,
675+
**kwargs:Any,
674676
)->Union[Dict[str,Any],requests.Response]:
675677
"""Make a POST request to the Gitlab server.
676678
@@ -717,7 +719,7 @@ def http_put(
717719
query_data:Optional[Dict[str,Any]]=None,
718720
post_data:Optional[Dict[str,Any]]=None,
719721
files:Optional[Dict[str,Any]]=None,
720-
**kwargs,
722+
**kwargs:Any,
721723
)->Union[Dict[str,Any],requests.Response]:
722724
"""Make a PUT request to the Gitlab server.
723725
@@ -755,7 +757,7 @@ def http_put(
755757
error_message="Failed to parse the server message"
756758
)frome
757759

758-
defhttp_delete(self,path:str,**kwargs)->requests.Response:
760+
defhttp_delete(self,path:str,**kwargs:Any)->requests.Response:
759761
"""Make a PUT request to the Gitlab server.
760762
761763
Args:
@@ -773,7 +775,7 @@ def http_delete(self, path: str, **kwargs) -> requests.Response:
773775

774776
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabSearchError)
775777
defsearch(
776-
self,scope:str,search:str,**kwargs
778+
self,scope:str,search:str,**kwargs:Any
777779
)->Union["GitlabList",List[Dict[str,Any]]]:
778780
"""Search GitLab resources matching the provided string.'
779781
@@ -806,7 +808,7 @@ def __init__(
806808
url:str,
807809
query_data:Dict[str,Any],
808810
get_next:bool=True,
809-
**kwargs,
811+
**kwargs:Any,
810812
)->None:
811813
self._gl=gl
812814

@@ -817,7 +819,7 @@ def __init__(
817819
self._get_next=get_next
818820

819821
def_query(
820-
self,url:str,query_data:Optional[Dict[str,Any]]=None,**kwargs
822+
self,url:str,query_data:Optional[Dict[str,Any]]=None,**kwargs:Any
821823
)->None:
822824
query_data=query_dataor {}
823825
result=self._gl.http_request("get",url,query_data=query_data,**kwargs)
@@ -842,7 +844,7 @@ def _query(
842844
self._total:Optional[Union[str,int]]=result.headers.get("X-Total")
843845

844846
try:
845-
self._data=result.json()
847+
self._data:List[Dict[str,Any]]=result.json()
846848
exceptExceptionase:
847849
raisegitlab.exceptions.GitlabParsingError(
848850
error_message="Failed to parse the server message"

‎gitlab/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
class_StdoutStream(object):
25-
def__call__(self,chunk)->None:
25+
def__call__(self,chunk:Any)->None:
2626
print(chunk)
2727

2828

@@ -31,7 +31,7 @@ def response_content(
3131
streamed:bool,
3232
action:Optional[Callable],
3333
chunk_size:int,
34-
):
34+
)->Optional[bytes]:
3535
ifstreamedisFalse:
3636
returnresponse.content
3737

@@ -41,6 +41,7 @@ def response_content(
4141
forchunkinresponse.iter_content(chunk_size=chunk_size):
4242
ifchunk:
4343
action(chunk)
44+
returnNone
4445

4546

4647
defcopy_dict(dest:Dict[str,Any],src:Dict[str,Any])->None:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp