Skip to content

chore: Put assert statements inside 'if TYPE_CHECKING:' #1350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions gitlab/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""Wrapper for the GitLab API."""

import time
from typing import cast, Any, Dict, List, Optional, Tuple, Union
from typing import cast, Any, Dict, List, Optional, Tuple, TYPE_CHECKING, Union

import requests
import requests.utils
Expand Down Expand Up @@ -266,7 +266,8 @@ def lint(self, content: str, **kwargs: Any) -> Tuple[bool, List[str]]:
"""
post_data = {"content": content}
data = self.http_post("/ci/lint", post_data=post_data, **kwargs)
assert isinstance(data, dict)
if TYPE_CHECKING:
assert not isinstance(data, requests.Response)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity: we didn't actually see this anywhere right, all the http_* methods process the result in some way?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity: we didn't actually see this anywhere right, all the http_* methods process the result in some way?

There are some calls where they do want the requests.Response object back from the http_* methods. As far as I can tell things want either one or the other. I don't see any (yet) that might expect either back.

return (data["status"] == "valid", data["errors"])

@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabMarkdownError)
Expand Down Expand Up @@ -294,7 +295,8 @@ def markdown(
if project is not None:
post_data["project"] = project
data = self.http_post("/markdown", post_data=post_data, **kwargs)
assert isinstance(data, dict)
if TYPE_CHECKING:
assert not isinstance(data, requests.Response)
return data["html"]

@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabLicenseError)
Expand Down Expand Up @@ -333,7 +335,8 @@ def set_license(self, license: str, **kwargs: Any) -> Dict[str, Any]:
"""
data = {"license": license}
result = self.http_post("/license", post_data=data, **kwargs)
assert isinstance(result, dict)
if TYPE_CHECKING:
assert not isinstance(result, requests.Response)
return result

def _set_auth_info(self) -> None:
Expand Down Expand Up @@ -855,7 +858,8 @@ def _query(
@property
def current_page(self) -> int:
"""The current page number."""
assert self._current_page is not None
if TYPE_CHECKING:
assert self._current_page is not None
return int(self._current_page)

@property
Expand All @@ -877,19 +881,22 @@ def next_page(self) -> Optional[int]:
@property
def per_page(self) -> int:
"""The number of items per page."""
assert self._per_page is not None
if TYPE_CHECKING:
assert self._per_page is not None
return int(self._per_page)

@property
def total_pages(self) -> int:
"""The total number of pages."""
assert self._total_pages is not None
if TYPE_CHECKING:
assert self._total_pages is not None
return int(self._total_pages)

@property
def total(self) -> int:
"""The total number of items."""
assert self._total is not None
if TYPE_CHECKING:
assert self._total is not None
return int(self._total)

def __iter__(self) -> "GitlabList":
Expand Down