Skip to content

Commit

Permalink
refactor: Replacing http_requests return type hint
Browse files Browse the repository at this point in the history
  • Loading branch information
lmilbaum committed Dec 19, 2022
1 parent 3e1c625 commit b6eedfc
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions gitlab/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ def http_request(
retry_transient_errors: Optional[bool] = None,
max_retries: int = 10,
**kwargs: Any,
) -> requests.Response:
) -> http_backends.DefaultResponse:
"""Make an HTTP request to the Gitlab server.
Args:
Expand Down Expand Up @@ -749,7 +749,7 @@ def http_request(
self._check_redirects(result.response)

if 200 <= result.status_code < 300:
return result.response
return result

def should_retry() -> bool:
if result.status_code == 429 and obey_rate_limit:
Expand Down Expand Up @@ -827,9 +827,10 @@ def http_get(
GitlabParsingError: If the json data could not be parsed
"""
query_data = query_data or {}
result = self.http_request(
response = self.http_request(
"get", path, query_data=query_data, streamed=streamed, **kwargs
)
result = response.response

if (
result.headers["Content-Type"] == "application/json"
Expand Down Expand Up @@ -1010,7 +1011,7 @@ def http_post(
query_data = query_data or {}
post_data = post_data or {}

result = self.http_request(
response = self.http_request(
"post",
path,
query_data=query_data,
Expand All @@ -1019,6 +1020,8 @@ def http_post(
raw=raw,
**kwargs,
)
result = response.response

try:
if result.headers.get("Content-Type", None) == "application/json":
json_result = result.json()
Expand Down Expand Up @@ -1095,7 +1098,8 @@ def http_delete(self, path: str, **kwargs: Any) -> requests.Response:
Raises:
GitlabHttpError: When the return code is not 2xx
"""
return self.http_request("delete", path, **kwargs)
response = self.http_request("delete", path, **kwargs)
return response.response

@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabSearchError)
def search(
Expand Down Expand Up @@ -1149,7 +1153,9 @@ def _query(
self, url: str, query_data: Optional[Dict[str, Any]] = None, **kwargs: Any
) -> None:
query_data = query_data or {}
result = self._gl.http_request("get", url, query_data=query_data, **kwargs)
response = self._gl.http_request("get", url, query_data=query_data, **kwargs)
result = response.response

try:
next_url = result.links["next"]["url"]
except KeyError:
Expand Down

0 comments on commit b6eedfc

Please sign in to comment.