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

Commitb562458

Browse files
chore: put assert statements inside 'if TYPE_CHECKING:'
To be safe that we don't assert while running, put the assertstatements, which are used by mypy to check that types are correct,inside an 'if TYPE_CHECKING:' block.Also, instead of asserting that the item is a dict, instead assertthat it is not a requests.Response object. Theoretically the JSONcould return as a list or dict, though at this time we are assuming adict.
1 parent5f23ed9 commitb562458

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

‎gitlab/client.py‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"""Wrapper for the GitLab API."""
1818

1919
importtime
20-
fromtypingimportcast,Any,Dict,List,Optional,Tuple,Union
20+
fromtypingimportcast,Any,Dict,List,Optional,Tuple,TYPE_CHECKING,Union
2121

2222
importrequests
2323
importrequests.utils
@@ -266,7 +266,8 @@ def lint(self, content: str, **kwargs: Any) -> Tuple[bool, List[str]]:
266266
"""
267267
post_data= {"content":content}
268268
data=self.http_post("/ci/lint",post_data=post_data,**kwargs)
269-
assertisinstance(data,dict)
269+
ifTYPE_CHECKING:
270+
assertnotisinstance(data,requests.Response)
270271
return (data["status"]=="valid",data["errors"])
271272

272273
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabMarkdownError)
@@ -294,7 +295,8 @@ def markdown(
294295
ifprojectisnotNone:
295296
post_data["project"]=project
296297
data=self.http_post("/markdown",post_data=post_data,**kwargs)
297-
assertisinstance(data,dict)
298+
ifTYPE_CHECKING:
299+
assertnotisinstance(data,requests.Response)
298300
returndata["html"]
299301

300302
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabLicenseError)
@@ -333,7 +335,8 @@ def set_license(self, license: str, **kwargs: Any) -> Dict[str, Any]:
333335
"""
334336
data= {"license":license}
335337
result=self.http_post("/license",post_data=data,**kwargs)
336-
assertisinstance(result,dict)
338+
ifTYPE_CHECKING:
339+
assertnotisinstance(result,requests.Response)
337340
returnresult
338341

339342
def_set_auth_info(self)->None:
@@ -855,7 +858,8 @@ def _query(
855858
@property
856859
defcurrent_page(self)->int:
857860
"""The current page number."""
858-
assertself._current_pageisnotNone
861+
ifTYPE_CHECKING:
862+
assertself._current_pageisnotNone
859863
returnint(self._current_page)
860864

861865
@property
@@ -877,19 +881,22 @@ def next_page(self) -> Optional[int]:
877881
@property
878882
defper_page(self)->int:
879883
"""The number of items per page."""
880-
assertself._per_pageisnotNone
884+
ifTYPE_CHECKING:
885+
assertself._per_pageisnotNone
881886
returnint(self._per_page)
882887

883888
@property
884889
deftotal_pages(self)->int:
885890
"""The total number of pages."""
886-
assertself._total_pagesisnotNone
891+
ifTYPE_CHECKING:
892+
assertself._total_pagesisnotNone
887893
returnint(self._total_pages)
888894

889895
@property
890896
deftotal(self)->int:
891897
"""The total number of items."""
892-
assertself._totalisnotNone
898+
ifTYPE_CHECKING:
899+
assertself._totalisnotNone
893900
returnint(self._total)
894901

895902
def__iter__(self)->"GitlabList":

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp