diff options
Diffstat (limited to 'gitlab')
-rw-r--r-- | gitlab/__init__.py | 4 | ||||
-rw-r--r-- | gitlab/base.py | 21 | ||||
-rw-r--r-- | gitlab/client.py | 15 | ||||
-rw-r--r-- | gitlab/mixins.py | 9 | ||||
-rw-r--r-- | gitlab/utils.py | 2 | ||||
-rw-r--r-- | gitlab/v4/objects/files.py | 5 | ||||
-rw-r--r-- | gitlab/v4/objects/keys.py | 2 | ||||
-rw-r--r-- | gitlab/v4/objects/packages.py | 2 | ||||
-rw-r--r-- | gitlab/v4/objects/projects.py | 6 | ||||
-rw-r--r-- | gitlab/v4/objects/users.py | 1 |
10 files changed, 50 insertions, 17 deletions
diff --git a/gitlab/__init__.py b/gitlab/__init__.py index 7b79f22..34f6619 100644 --- a/gitlab/__init__.py +++ b/gitlab/__init__.py @@ -32,3 +32,7 @@ from gitlab.const import * # noqa: F401,F403 from gitlab.exceptions import * # noqa: F401,F403 warnings.filterwarnings("default", category=DeprecationWarning, module="^gitlab") + +__all__ = [ + "Gitlab", +] diff --git a/gitlab/base.py b/gitlab/base.py index 5e5f57b..8dcae7d 100644 --- a/gitlab/base.py +++ b/gitlab/base.py @@ -17,7 +17,17 @@ import importlib from types import ModuleType -from typing import Any, Dict, Iterable, NamedTuple, Optional, Tuple, Type +from typing import ( + Any, + Dict, + Iterable, + NamedTuple, + Optional, + Tuple, + Type, + TYPE_CHECKING, + Union, +) from gitlab import types as g_types from gitlab.exceptions import GitlabParsingError @@ -172,15 +182,18 @@ class RESTObject(object): self.__dict__["_updated_attrs"] = {} self.__dict__["_attrs"] = new_attrs - def get_id(self) -> Any: + def get_id(self) -> Optional[Union[int, str]]: """Returns the id of the resource.""" if self._id_attr is None or not hasattr(self, self._id_attr): return None - return getattr(self, self._id_attr) + id_val = getattr(self, self._id_attr) + if TYPE_CHECKING: + assert isinstance(id_val, (int, str)) + return id_val @property def attributes(self) -> Dict[str, Any]: - d = self.__dict__["_updated_attrs"].copy() + d: Dict[str, Any] = self.__dict__["_updated_attrs"].copy() d.update(self.__dict__["_attrs"]) d.update(self.__dict__["_parent_attrs"]) return d diff --git a/gitlab/client.py b/gitlab/client.py index 295712c..467c5dc 100644 --- a/gitlab/client.py +++ b/gitlab/client.py @@ -337,6 +337,7 @@ class Gitlab(object): data = self.http_post("/markdown", post_data=post_data, **kwargs) if TYPE_CHECKING: assert not isinstance(data, requests.Response) + assert isinstance(data["html"], str) return data["html"] @gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabLicenseError) @@ -614,10 +615,13 @@ class Gitlab(object): cur_retries = 0 while True: result = self.session.send(prepped, timeout=timeout, **settings) + print("result type:", type(result)) + print("result:", result) self._check_redirects(result) if 200 <= result.status_code < 300: + print("Returning result:", result) return result retry_transient_errors = kwargs.get( @@ -694,7 +698,8 @@ class Gitlab(object): and not raw ): try: - return result.json() + data: Dict[str, Any] = result.json() + return data except Exception as e: raise gitlab.exceptions.GitlabParsingError( error_message="Failed to parse the server message" @@ -791,7 +796,10 @@ class Gitlab(object): ) try: if result.headers.get("Content-Type", None) == "application/json": - return result.json() + print("data.text:", result.text) + data: Dict[str, Any] = result.json() + print("data type:", type(data)) + return data except Exception as e: raise gitlab.exceptions.GitlabParsingError( error_message="Failed to parse the server message" @@ -839,7 +847,8 @@ class Gitlab(object): **kwargs, ) try: - return result.json() + data: Dict[str, Any] = result.json() + return data except Exception as e: raise gitlab.exceptions.GitlabParsingError( error_message="Failed to parse the server message" diff --git a/gitlab/mixins.py b/gitlab/mixins.py index 0159ecd..785e3c5 100644 --- a/gitlab/mixins.py +++ b/gitlab/mixins.py @@ -573,9 +573,11 @@ class ObjectDeleteMixin(_RestObjectBase): GitlabAuthenticationError: If authentication is not correct GitlabDeleteError: If the server cannot perform the request """ + id_val = self.get_id() if TYPE_CHECKING: assert isinstance(self.manager, DeleteMixin) - self.manager.delete(self.get_id(), **kwargs) + assert id_val is not None + self.manager.delete(id_val, **kwargs) class UserAgentDetailMixin(_RestObjectBase): @@ -652,7 +654,7 @@ class DownloadMixin(_RestObjectBase): def download( self, streamed: bool = False, - action: Optional[Callable] = None, + action: Optional[Callable[[bytes], None]] = None, chunk_size: int = 1024, **kwargs: Any, ) -> Optional[bytes]: @@ -779,7 +781,8 @@ class TimeTrackingMixin(_RestObjectBase): # Use the existing time_stats attribute if it exist, otherwise make an # API call if "time_stats" in self.attributes: - return self.attributes["time_stats"] + time_stats: Dict[str, Any] = self.attributes["time_stats"] + return time_stats path = f"{self.manager.path}/{self.get_id()}/time_stats" result = self.manager.gitlab.http_get(path, **kwargs) diff --git a/gitlab/utils.py b/gitlab/utils.py index 220a8c9..196210c 100644 --- a/gitlab/utils.py +++ b/gitlab/utils.py @@ -29,7 +29,7 @@ class _StdoutStream(object): def response_content( response: requests.Response, streamed: bool, - action: Optional[Callable], + action: Optional[Callable[[bytes], None]], chunk_size: int, ) -> Optional[bytes]: if streamed is False: diff --git a/gitlab/v4/objects/files.py b/gitlab/v4/objects/files.py index ce7317d..fa4d744 100644 --- a/gitlab/v4/objects/files.py +++ b/gitlab/v4/objects/files.py @@ -76,7 +76,10 @@ class ProjectFile(SaveMixin, ObjectDeleteMixin, RESTObject): GitlabAuthenticationError: If authentication is not correct GitlabDeleteError: If the server cannot perform the request """ - file_path = self.get_id().replace("/", "%2F") + id_val = self.get_id() + if TYPE_CHECKING: + assert isinstance(id_val, str) + file_path = id_val.replace("/", "%2F") self.manager.delete(file_path, branch, commit_message, **kwargs) diff --git a/gitlab/v4/objects/keys.py b/gitlab/v4/objects/keys.py index 46f6894..c03dced 100644 --- a/gitlab/v4/objects/keys.py +++ b/gitlab/v4/objects/keys.py @@ -31,4 +31,4 @@ class KeyManager(GetMixin, RESTManager): server_data = self.gitlab.http_get(self.path, **kwargs) if TYPE_CHECKING: assert isinstance(server_data, dict) - return cast(Key, self._obj_cls(self, server_data)) + return self._obj_cls(self, server_data) diff --git a/gitlab/v4/objects/packages.py b/gitlab/v4/objects/packages.py index 0062067..55e45a3 100644 --- a/gitlab/v4/objects/packages.py +++ b/gitlab/v4/objects/packages.py @@ -103,7 +103,7 @@ class GenericPackageManager(RESTManager): package_version: str, file_name: str, streamed: bool = False, - action: Optional[Callable] = None, + action: Optional[Callable[[bytes], None]] = None, chunk_size: int = 1024, **kwargs: Any, ) -> Optional[bytes]: diff --git a/gitlab/v4/objects/projects.py b/gitlab/v4/objects/projects.py index c5ce717..6fd60f4 100644 --- a/gitlab/v4/objects/projects.py +++ b/gitlab/v4/objects/projects.py @@ -436,7 +436,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO self, wiki: bool = False, streamed: bool = False, - action: Optional[Callable] = None, + action: Optional[Callable[[bytes], None]] = None, chunk_size: int = 1024, **kwargs: Any, ) -> Optional[bytes]: @@ -531,7 +531,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO ref_name: str, job: str, streamed: bool = False, - action: Optional[Callable] = None, + action: Optional[Callable[[bytes], None]] = None, chunk_size: int = 1024, **kwargs: Any, ) -> Optional[bytes]: @@ -574,7 +574,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO artifact_path: str, job: str, streamed: bool = False, - action: Optional[Callable] = None, + action: Optional[Callable[[bytes], None]] = None, chunk_size: int = 1024, **kwargs: Any, ) -> Optional[bytes]: diff --git a/gitlab/v4/objects/users.py b/gitlab/v4/objects/users.py index bf7d283..bced3fc 100644 --- a/gitlab/v4/objects/users.py +++ b/gitlab/v4/objects/users.py @@ -181,6 +181,7 @@ class User(SaveMixin, ObjectDeleteMixin, RESTObject): """ path = f"/users/{self.id}/block" server_data = self.manager.gitlab.http_post(path, **kwargs) + print(type(server_data)) if server_data is True: self._attrs["state"] = "blocked" return server_data |